Re: re:Timing out an fgets

From: Date: Fri, 18 Aug 2000 05:18:53 +0000
Subject: Re: re:Timing out an fgets
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-12405@lists.php.net to get a copy of this message
> > while( connection_timeout() == "FALSE" ) { > > fgets($fp, 1024) > > or die("Error no response recieved"); > > if ( connection_timeout() == "TRUE" ) { > > die("Connection timed out"); > > } > > } > > > > When I try this in my script it jumps straight to TRUE and says 'Connection timed > > out' this is in like 1 second, so I really don't get it, further more if the > > max_execution_time was working the timeout should be 1 minute as per the manual > > because as far as I can tell the set_time_limit is added to the max_execution_time. > > > > Am I using this right anyone? > > Remember that (the string) "TRUE" is not the same as (boolean) TRUE. You > can check the boolean value of the response from connection_timeout just > by doing if (connection_timeout() ). But you can use the predefined TRUE and FALSE values. So if (connection_timeout() == TRUE) But, I think they are defined to be: TRUE 1 FALSE 0 So, if for somereason, connection_timeout() returned 2, then (connection_timeout() == TRUE) would not be true. it is correct to check like this: if (connection_timeout()) This is true throughout PHP. You have to just know what your function returns. But, I don't think that connection_timeout() is what you want... you just want fgets to fail. According to the php manual, fgets() returns a string on success and a FALSE on failure. So, you should be able to do something like this: while (!feof($file_pointer)) { $string = fgets($file_pointer, 128); if ($string == FALSE) print "it didn't happen\n"; else { /* do something with the string */ $bigger_string .= $string; } } Question, if you can connect to the server anyway and get your valid file pointer, then what protocol are you speaking... for example, if you get your file_pointer be using fsockopen() then you had better send a request your self first to get something back.. on a web server, you would first have to $foo = "GET / HTTP/1.1\r\n\r\n"; fwrite($file_pointer, $foo, strlen($foo)); Then, you should be able to receive data... Otherwise, of course it is going to just hang... :) -jeremy brand _______________________________________________________________________ GnuPG Fingerprint: 9F5E 95E0 1CC2 E054 84EA 6099 8ACD 9DBA D2C0 5EA9 _ http://www.jeremybrand.com/jeremy/brand/jeremy_brand.html for more __

« previous php.general (#12405) next »