Question

I am working on server/client php scripts which can communicate over a UDP socket. I was wondering if there is a good way to implement a timeout() for the socket_recv() function. Currently it is blocking in my client, waiting for an ack.

Thanks for your input!

Was it helpful?

Solution

I found the solution to my question: socket_set_option() has the option SO_RCVTIMEO which set a timeout just for socket_recv()

for example:

socket_set_option($sock,SOL_SOCKET,SO_RCVTIMEO,array("sec"=>1,"usec"=>0));

This will set a timeout on my socket on the socket level for socket_recv() for 1second and 0 microseconds http://www.php.net/manual/en/function.socket-set-option.php

Thank you if you looked for a solution!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top