stream_socket_accept()
stream_socket_accept() — Accept a connection on a socket created by stream_socket_server().
Built-in function of PHP 8.5. The manual lists it as available in PHP 5, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.
Signature
stream_socket_accept(resource $socket, ?float $timeout = null, string &$peer_name = null): resource|false
Parameters
| Parameter | Type | What it takes |
|---|---|---|
| $socket | resource | The server socket to accept a connection from. |
| $timeout | ?float | Override the default socket accept timeout. Time should be given in seconds. By default, default_socket_timeout is used. |
| &$peer_name | string | Will be set to the name (address) of the client which connected, if included and available from the selected transport. |
Return value
Returns a stream to the accepted socket connection or false on failure.
Example
The PHP manual ships no example for stream_socket_accept(); the signature and the parameter table above are the contract.
Changelog
| Version | Change |
|---|---|
| 8.0.0 | timeout is now nullable. |
See also
stream_socket_server(), stream_socket_get_name(), stream_set_blocking(), stream_set_timeout(), fgets(), fwrite(), fclose(), feof()
All PHP 8.5 built-in functions
Reference card built from the PHP manual page stream_socket_accept() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.