James Hartig James Hartig - 1 year ago 133
PHP Question

Set a timeout on socket_read

I was wondering how can I set a timeout on a

call? The first time it calls
, it waits till data is sent, and if no data is sent within 5 secs I want to shutdown the connection. Any Help? I already tried
with no luck.

I'm creating a socket with
and listening on it for connections, then when connected I listen for the data and then do something with it. When the timeout hits, I want to run
and then

Answer Source

I did a socket_listen and then I made a manual timeout with time()+2 and a while loop with nonblock set and socket_read() inside. Seems to be working ok. Any alternatives?

UPDATE: I found that setting the socket as nonblocking and then using socket_listen provided the timeout I needed.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download