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
Mostrar archivo Open project: varspool/Wrench Class Usage Examples

Protected Properties

Property 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

Public Methods

Method 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

Protected Methods

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

Method Details

configure() protected method

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

disconnect() public method

Disconnect the socket
public disconnect ( ) : void
return void

getIp() public method

Gets the IP address of the socket
public getIp ( ) : string
return string

getLastError() public method

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

getName() protected method

Gets the name of the socket
protected getName ( ) : string
return string

getNamePart() public static method

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)
return string

getPort() public method

Gets the port of the socket
public getPort ( ) : string
return string

getResource() public method

public getResource ( )

getResourceId() public method

public getResourceId ( )

isConnected() public method

Whether the socket is currently connected
public isConnected ( ) : boolean
return boolean

receive() public method

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

send() public method

public send ( string $data ) : boolean | integer
$data string Binary data to send down the socket
return 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
return 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
return boolean

$name protected_oe property

The socket name according to stream_socket_get_name
protected string $name
return string

$socket protected_oe property

protected resource $socket
return resource