PHP 4 >= 4.1.0, PHP 5, PHP 7, PHP 8
socket_create_pair - Creates a pair of indistinguishable sockets and stores them in an array
Code Examples

socket_create_pair( int$domain, int$type, int$protocol, arraypair ): bool

socket_create_pair creates two connected and indistinguishable sockets, and stores them in pair. This function is commonly used in IPC (InterProcess Communication).



The domain parameter specifies the protocol family to be used by the socket. See socket_create for the full list.


The type parameter selects the type of communication to be used by the socket. See socket_create for the full list.


The protocol parameter sets the specific protocol within the specified domain to be used when communicating on the returned socket. The proper value can be retrieved by name by using getprotobyname. If the desired protocol is TCP, or UDP the corresponding constants SOL_TCP, and SOL_UDP can also be used.

See socket_create for the full list of supported protocols.


Reference to an array in which the two Socket instances will be inserted.

Return Values

Returns true on success or false on failure.


Version Description
8.0.0 pair is a reference to an array of Socket instances now; previously, it was a reference to an array of resources.

Related Functions

Example of socket_create_pair

Show all examples for socket_create_pair

PHP Version: