Timeout on fread

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Timeout on fread

Post 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
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Post 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);
?>
rehfeld
Forum Regular
Posts: 741
Joined: Mon Oct 18, 2004 8:14 pm

Post by rehfeld »

$time+3 will always be greater than $time
you want $time+3>time()
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post 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 :-)
Post Reply