A community in which webmasters can ask for help with topics such as PHP coding , MySQL , IT jobs, web design, IT security.
Current location:homephp forumphp talk in 2008 yearSet a timeout on socket_read - page 1
User InfoPosts
Set a timeout on socket_read#1
I was wondering how can I set a timeout on a socket_read call? The first time it calls socket_read, 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 SO_RCVTIMEO with no luck.

I'm creating a socket with socket_create() 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 socket_shutdown() and then socket_close().

posted date: 2008-12-23 10:15:00

Re: Set a timeout on socket_read#2
I had made out the solution of this problem. click to view my topic...

hope that hepls.

posted date: 2008-12-23 10:15:01

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 socket_read() 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 »
Copyright ©2008-2017 www.momige.com, all rights reserved.