|Set a timeout on socket_read||#1|
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
posted date: 2008-12-23 10:15:00
|Re: Set a timeout on socket_read||#3|
posted date: 2008-12-23 10:19:00
|Re: Set a timeout on socket_read||#4|
that doesn't work on socket_create() sockets, at least it doesn't seem to work
posted date: 2008-12-23 10:23:00
|Re: Set a timeout on socket_read||#5|
Have you tried socket_set_option with SO_RCVTIMEOTimeout value for input operations.
posted date: 2008-12-23 10:58:00
|Re: Set a timeout on socket_read||#6|
I tried! I think I found a solution with socket_listen and a manual timeout with time()+2 and a while.
posted date: 2008-12-23 11:09:00
|Re: Set a timeout on socket_read||#7|
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.
posted date: 2008-12-23 11:11:00
|Re: Set a timeout on socket_read||#8|
Oooh, you're accepting socket connections with PHP. That's a bit different. us3.php.net/manual/en/function.socket-select.php Select will return sockets if there is anything available to be read, otherwise time out with your specified timeout.
posted date: 2008-12-23 11:49:00
|Re: Set a timeout on socket_read||#9|
Brilliant! That solved it for me. I now have a
that times out for me.
posted date: 2010-01-04 00:24:00
|Re: Set a timeout on socket_read||#10|
this set 5 sec timeout of the socket.
socket_set_option($socket,SOL_SOCKET, SO_RCVTIMEO, array("sec"=>5, "usec"=>0));
posted date: 2011-11-20 15:09:00
|Re: Set a timeout on socket_read||#11|
this worked for me. i think this is the proper way to do it.
posted date: 2011-12-13 12:12:00
|Re: Set a timeout on socket_read||#12|
after some testing - this appears to be the lifetime of the entire socket - no just the socket_read
posted date: 2011-12-15 15:18:00
|select page: « 1 2 »|