PHP Function Stream_Socket_Shutdown
php function stream_socket_shutdown is a very useful little function that ensures that all client streams opened with the stream_socket_client / stream_socket_server functions are disconnected and no longer receiving or transmitting data. This is necessary since some operating systems only flush file output on a close call (and not on fclose()). Without this functionality, you could end up with severe data-eating errors in case the OS fails to do so.
This is especially important if you use the symlink mechanism to open multiple streams from the same source. If you don't disconnect all of the client streams, a failure in one may corrupt the entire set of data.
In addition to the general stream options, STREAM_NOTIFY_SEVERITY_ERR and STREAM_NOTIFY_WARNING flags are also available. STREAM_NOTIFY_SEVERITY_ERR informs the stream that it has encountered an error; a specific error message and code can be obtained by examining the message field of the corresponding stream context. STREAM_NOTIFY_WARNING informs the stream that a non-critical event occurred, typically indicating that additional authorization is required to access an external resource.
There are a variety of built-in wrappers for handling common protocols/encodings (see List of Supported Protocols/Wrappers). Additional user designed wrappers can be registered using stream_wrapper_register() and the class definition found on that manual page.
Generally, the fread() function in PHP is a bit more generic than the corresponding stream_*() family of functions which operate on sockets. This is because the fopen() function can be used to fopen a Web page, local file or compressed archive while the stream_socket_*() functions work with out-of-band data channels.