Abstract parent to all sockets.
Protected Properties | |
resource | $resource |
The underlying PHP resource. More... | |
Public Static Methods | |
static self | create (int $domain=AF_INET,... $extra) |
Creates an instance of the called class. More... | |
static int | getType () |
The SOCK_* type constant for the class. More... | |
Public Methods | |
__construct ($resource) | |
Validates and sets the underlying socket resource. More... | |
__destruct () | |
Closes the socket if it's open. More... | |
$this | await (int $channel) |
Blocks until the socket becomes available on a given channel. More... | |
$this | awaitOutOfBand () |
$this | awaitReadable () |
$this | awaitWritable () |
$this | close () |
Closes the underlying resource if it's open. More... | |
int | getDomain () |
The AF_* address family constant. More... | |
int | getId () |
mixed | getOption (int $option) |
Retrieves an option value. More... | |
resource | getResource () |
array | getSockName () |
The local address and port, or Unix file path and port 0 . More... | |
bool | isOpen () |
bool | isOutOfBand () |
Polls for whether the socket can perform a non-blocking out-of-band read. More... | |
bool | isReadable () |
Polls for whether the socket can perform a non-blocking read. More... | |
bool | isReady (int $channel, ?float $timeout=0) |
Selects for channel availability. More... | |
bool | isWritable () |
Polls for whether the socket can perform a non-blocking write. More... | |
$this | setBlocking (bool $blocking) |
Enables or disables blocking. More... | |
$this | setOption (int $option, $value) |
Sets an option on the underlying resource. More... | |
$this | setTimeout (float $timeout) |
Sets the I/O timeout length in seconds. More... | |
$this | shutdown (int $channel) |
Shuts down I/O for a single channel. More... | |
Additional Inherited Members | |
Public Properties inherited from SocketInterface | |
const | CH_EXCEPT = 2 |
Out-of-band channel. More... | |
const | CH_READ = 0 |
Read channel. More... | |
const | CH_WRITE = 1 |
Write channel. More... | |
|
protected |
The underlying PHP resource.
__construct | ( | $resource | ) |
Validates and sets the underlying socket resource.
The resource must be open, of the correct type, and have no pending errors.
resource | $resource | PHP socket resource. |
InvalidArgumentException | Not a socket resource, or the socket is of the wrong type. |
SocketError | Slippage of an existing error on the resource. |
__destruct | ( | ) |
Closes the socket if it's open.
$this await | ( | int | $channel | ) |
Blocks until the socket becomes available on a given channel.
Throws if the underlying resource has a pending error (non-blocking sockets only).
int | $channel | SocketInterface channel constant. |
SocketError |
$this close | ( | ) |
|
static |
Creates an instance of the called class.
int | $domain | AF_* constant. |
array | $extra | Variadic constructor arguments. |
SocketError |
|
final |
The AF_*
address family constant.
|
final |
Implements SocketInterface.
mixed getOption | ( | int | $option | ) |
Retrieves an option value.
int | $option | SO_* option constant. |
false
. SocketError |
|
final |
Implements SocketInterface.
array getSockName | ( | ) |
The local address and port, or Unix file path and port 0
.
[ 0 => address, 1 => port ]
SocketError |
|
staticabstract |
The SOCK_*
type constant for the class.
Reimplemented in DatagramClient, DatagramServer, StreamClient, and StreamServer.
bool isOpen | ( | ) |
Implements SocketInterface.
|
final |
Polls for whether the socket can perform a non-blocking out-of-band read.
|
final |
bool isReady | ( | int | $channel, |
?float | $timeout = 0 |
||
) |
Selects for channel availability.
int | $channel | SocketInterface channel constant. |
float | null | $timeout | Maximum seconds to block. NULL blocks forever. Defaults to a poll. |
SocketError |
|
final |
$this setBlocking | ( | bool | $blocking | ) |
Enables or disables blocking.
Note: PHP provides no way to retrieve a socket's blocking mode.
Sockets are always created in blocking mode.
If you're using a reactor, keep the sockets in blocking mode.
Non-blocking errors are thrown when performing ordinary operations, even if unrelated to those operations. This is known as error slippage. To test for and clear an existing non-blocking error, use ->getOption(SO_ERROR)
.
bool | $blocking | Whether the socket should block. |
SocketError |
$this setOption | ( | int | $option, |
$value | |||
) |
Sets an option on the underlying resource.
int | $option | SO_* constant. |
mixed | $value |
SocketError |
$this setTimeout | ( | float | $timeout | ) |
Sets the I/O timeout length in seconds.
float | $timeout | Zero means "no timeout" (block forever). |
$this shutdown | ( | int | $channel | ) |
Shuts down I/O for a single channel.
Shutting down is a formal handshake two peers can do before actually closing. It's not required, but it can help assert I/O access logic.
If writing is shut down, trying to send will throw SOCKET_EPIPE
, and the remote peer will read an empty string after receiving all pending data.
If reading is shut down, trying to receive will return an empty string, and the remote peer will get an EPIPE
error if they try to send.
Writing should be shut down first between two connected sockets.
Selection always returns positive for a shut down channel, and the remote peer will similarly have positive selection for the opposite channel.
int | $channel | CH_READ or CH_WRITE |
SocketError |