Stream Socket Functions in PHP
PHP supports a variety of stream related functions that provide more specific functionality for sockets. Unlike the general fwrite and fread function that operate on file/network or data compression, these functions are specifically oriented towards sockets. The stream_socket_*() family of functions, for instance, support out-of-band data channels and multiplexing of another data stream via a single connection.
Generally, these functions are used in conjunction with other stream related functions (stream_socket_accept, iostream_set_timeout, etc). For example, if a server is accepting client connections but not yet delivering output to the clients, you may want to use the iostream_set_timeout() function to limit how long it takes for the server to deliver output to the client.
Another useful feature is that these functions typically allow you to set various options for the operation. For example, when reading from an SSL enabled stream using fread(), if the server has sent decrypted data, you can use a specialized function such as stream_socket_recvfrom() to read back the original, encrypted bytes.
Lastly, it is important to remember that like any other file or network related call in PHP, these functions may return an error for a variety of normal reasons. These errors can be logged in the errno and errstr arrays. In addition, if the stream is being created on a system level socket and the bind() or listen() function fails then an E_WARNING may be generated indicating the nature of the error. In addition, the STREAM_GET_Wrappers() function provides a list of available wrappers for the running installation of PHP.