Re: socket timeout

From: Date: Thu, 05 Dec 2002 20:00:10 +0000
Subject: Re: socket timeout
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-127194@lists.php.net to get a copy of this message
--- Gareth Thomas <gdthomas@mercurysoft.com> wrote: > I am attempting to timeout a socket_read() that is part > of a handshaking process using socket_set_timeout(). > Problem is it doesn't seem to work at all. If I switch of > the handshaking write on the server side the read just > sits there and doesn't time out at all. I have tried > socket_set_timeout($socket,1) which I believe is 1 second > and it never times out... My bet is that you are only setting the timeout but not ever checking to see whether the socket has timed out. If you want to only read from the socket until it times out, you need to add that to your logic. Try something like this: socket_set_timeout($fp, $timeout_seconds); $response=""; # Get socket status $socket_status = socket_get_status($fp); # Read response up to 128 bytes at a time until EOF or socket times out while(!feof($fp) && !$socket_status["timed_out"]) { $response .= fgets($fp, "128"); $socket_status = socket_get_status($fp); } Chris

« previous php.general (#127194) next »