Php – How to tell if socket is open in PHP

PHPsockets

I am required to maintain a few sockets that I opened with PHP and check those sockets at regular intervals. I am new to sockets in PHP; I opened the sockets like this:

$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); 
socket_connect($socket, $ip, $port);

Some of the sockets can get into a state where they don't return messages; these sockets only receive messages. How can I tell if a socket is opened if the socket does not respond to a message?

Best Answer

socket_sendto — Sends a message to a socket, whether it is connected or not

Seems like you could use socket_sendto and send some 'ping' data to the remote host, then test the return value to determine if the socket is still established.