stream_socket_accept

(PHP 5, PHP 7, PHP 8)

stream_socket_acceptAccept a connection on a socket created by stream_socket_server()

Description

stream_socket_accept(resource$socket, ?float$timeout = null, string&$peer_name = null): resource|false

Accept a connection on a socket previously created by stream_socket_server().

Parameters

socket

The server socket to accept a connection from.

timeout

Override the default socket accept timeout. Time should be given in seconds. By default, default_socket_timeout is used.

peer_name

Will be set to the name (address) of the client which connected, if included and available from the selected transport.

Note:

Can also be determined later using stream_socket_get_name().

Return Values

Returns a stream to the accepted socket connection or false on failure.

Changelog

VersionDescription
8.0.0timeout is now nullable.

Notes

Warning

This function should not be used with UDP server sockets. Instead, use stream_socket_recvfrom() and stream_socket_sendto().

See Also

To Top