re:Timing out an fgets

From: Date: Thu, 17 Aug 2000 00:24:42 +0000
Subject: re:Timing out an fgets
Groups: php.general 
Request: Send a blank email to php-general+get-12130@lists.php.net to get a copy of this message
Hey php'ers I am currently developing a client for a server application, it is near completion but I still have to cover a few error conditions one being no response from the server at all. The application im using has provision to test this situation and allows you to send packets to it but will not respond at all. My problem is I am using fgets to receive a result from the server, but every time I test for this condition it just sits there trying and eventually ( after about 5 mins ) says page cannot be displayed. My question is how would I go about setting a time-out for the fgets command so that I may retry a number of times before sending a error message. I have tried something like this, of course I have already opened a socket and $pck would hold the info im trying to send. ... $i = 0; while( !fgets($fp, 1024) ) { if ( $i <= 2 ) { sleep(10); fputs($fp, $pck); or die("Error connecting to remote host"); } else { die("Maximum retry count reached"); } if ( fgets($fp, 1024) ) { break; } else { $i++; continue; } } ... The above code would handle the retries, but not a timeout as fgets just seems to keep trying until the browser timesout the page? Any help would be much appreciated. ] Regards, Joseph Blythe

« previous php.general (#12130) next »