From socket_read () :
socket_read () returns the data as a string on success, or FALSE on error
(including if the remote host has closed the connection). The error code can
be retrieved with socket_last_error (). This code may be passed to
socket_strerror () to get a textual representation of the error.
This is a pretty standard detection approach if the socket is closed in most languages. I do not believe that PHP offers a direct notification of the style of the event (with the possible exception of something in PEAR).
source share