I have the following problem. I create a socket on a port. I set it to listen and than I want to connect to that socket. If someone connects, all goes fine. But if the connection doesn't come, my script stays waiting untill someone connects. I don't have any wrong loops but he just waits at socket_accept() untill a connection is made. It's very strange. Who can help me??

Code where it goes wrong:

if (($msgsock = socket_accept($sock)) < 0) {
          	echo "socket_accept() failed: reason: " . socket_strerror($msgsock) . "\n";
    	}

    No it doesn't work. It only works for fopen and fsockopen connections.

    I found the answer myself on the BUG forum of PHP. It's a known bug. When a socket is in blocking mode and you use socket_accept() the script will not respond and will not react on any interrupt until a connection is made.

    The way to solve is very easy: socket_set_blocking() and set blocking off.

    Tanks for the people who have tried to help me.

      Write a Reply...