I try to use a local socket to communicate to another process that is running on the same host (PHP 7.1 on Linux):
$socket_fd = @socket_create(AF_UNIX, SOCK_SEQPACKET, 0);
socket_set_option($socket_fd, SOL_SOCKET, SO_RCVTIMEO, array('sec' => 1, 'usec' => 0));
socket_set_option($socket_fd, SOL_SOCKET, SO_SNDTIMEO, array('sec' => 1, 'usec' => 0));
if (@socket_connect($socket_fd, "/mypath/mysocket.sock"))
{ // so something
}
As you can see, I have already tried the solution to the similar question Make PHP socket_connect timeout but that doesn't seem to work for local sockets.
If the program on the other side hangs, socket_connect
never runs into a timeout, it just hangs forever.
Is there a way to do it?