PHP Class Wrench\Socket\Socket

Implements low level logic for connecting, serving, reading to, and writing from WebSocket connections using PHP's streams. Unlike in previous versions of this library, a Socket instance now represents a single underlying socket resource. It's designed to be used by aggregation, rather than inheritance.
Inheritance: extends Wrench\Util\Configurable, implements Wrench\Resource
Afficher le fichier Open project: varspool/Wrench Class Usage Examples

Protected Properties

Свойство Type Description
$connected boolean Note, the connection may not be ready to use, but the socket is connected at least. See $handshaked, and other properties in subclasses.
$context Stream context
$firstRead boolean Whether the current read is the first one to the socket
$name string The socket name according to stream_socket_get_name
$socket resource

Méthodes publiques

Méthode Description
disconnect ( ) : void Disconnect the socket
getIp ( ) : string Gets the IP address of the socket
getLastError ( ) : integer | string Get the last error that occurred on the socket
getNamePart ( string $name, $part ) : string Gets part of the name of the socket
getPort ( ) : string Gets the port of the socket
getResource ( )
getResourceId ( )
isConnected ( ) : boolean Whether the socket is currently connected
receive ( integer $length = self::DEFAULT_RECEIVE_LENGTH ) : string Receive data from the socket
send ( string $data ) : boolean | integer

Méthodes protégées

Méthode Description
configure ( array $options ) : void Configure options
getName ( ) : string Gets the name of the socket

Method Details

configure() protected méthode

Options include - timeout_socket => int, seconds, default 5
protected configure ( array $options ) : void
$options array
Résultat void

disconnect() public méthode

Disconnect the socket
public disconnect ( ) : void
Résultat void

getIp() public méthode

Gets the IP address of the socket
public getIp ( ) : string
Résultat string

getLastError() public méthode

Get the last error that occurred on the socket
public getLastError ( ) : integer | string
Résultat integer | string

getName() protected méthode

Gets the name of the socket
protected getName ( ) : string
Résultat string

getNamePart() public static méthode

PHP seems to return IPV6 address/port combos like this: ::1:1234, where ::1 is the address and 1234 the port So, the part number here is either the last : delimited section (the port) or all the other sections (the whole initial part, the address).
public static getNamePart ( string $name, $part ) : string
$name string (from $this->getName() usually)
Résultat string

getPort() public méthode

Gets the port of the socket
public getPort ( ) : string
Résultat string

getResource() public méthode

public getResource ( )

getResourceId() public méthode

public getResourceId ( )

isConnected() public méthode

Whether the socket is currently connected
public isConnected ( ) : boolean
Résultat boolean

receive() public méthode

Receive data from the socket
public receive ( integer $length = self::DEFAULT_RECEIVE_LENGTH ) : string
$length integer
Résultat string

send() public méthode

public send ( string $data ) : boolean | integer
$data string Binary data to send down the socket
Résultat boolean | integer The number of bytes sent or false on error

Property Details

$connected protected_oe property

Note, the connection may not be ready to use, but the socket is connected at least. See $handshaked, and other properties in subclasses.
protected bool $connected
Résultat boolean

$context protected_oe property

Stream context
protected $context

$firstRead protected_oe property

Whether the current read is the first one to the socket
protected bool $firstRead
Résultat boolean

$name protected_oe property

The socket name according to stream_socket_get_name
protected string $name
Résultat string

$socket protected_oe property

protected resource $socket
Résultat resource