Page 1 of 1

Timeout on fread

Posted: Fri Dec 17, 2004 1:24 pm
by josh
Correct me if I am wrong, shouldn't the following code time out after 3 seconds, so if the file I am reading from doesn't exist it will give up instead of freezeing up

Code: Select all

<?php
	$xml = '';
	$time=time();
	$File=fopen($uFile, "rb");
	while (!feof($File) AND $time+3>$time) {
	  $xml .= fread(uFile, 8192);
	}
	fclose($File);
?>
A site I was getting an xml data feed from went down and I noticed my code wasn't working, was my server just lagging or is there an error in my code.

Thank you in advance

Posted: Fri Dec 17, 2004 1:42 pm
by Joe
Not sure here but try:

Code: Select all

<?php    
$xml = '';    
$time=time();    
$File=fopen($uFile, "rb");    
while (!feof($File)) {
 if ($time+3>$time) break;
 $xml .= fread(uFile, 8192);    
}    
fclose($File);
?>

Posted: Fri Dec 17, 2004 2:15 pm
by rehfeld
$time+3 will always be greater than $time
you want $time+3>time()

Posted: Fri Dec 17, 2004 2:39 pm
by josh
Opps my bad, when you type code at like 2 AM you tend to make stupid mistakes like putting the variable $time instead of the function time().... heh

If only computers did what you want them to do instead of what you tell them to do :-)