Forum Moderators: coopster

Message Too Old, No Replies

while(!feof($fp) generates loop

         

globay

2:30 pm on Nov 15, 2003 (gmt 0)

10+ Year Member



I use the following code, to 'read' a remote file:

if (file_exists($xmlloc)){
$data = implode('', file($xmlloc));
}
else {
$fp = fopen($xmlloc,'r');
while(!feof($fp)){
$data = $data . fread($fp, 1024);
}

fclose($fp);

Unfortunately sometimes the file that I am trying to access is not available, and I get a 500 error as a reply, which produces an infinite loop in while(!feof($fp)), and thus infinite Warning messages, which are eating up my bandwidth.

Does anybody know how to modify the script, or how to turn off error messages in PHP?

Thank you for your help,
globay

ikbenhet1

2:40 pm on Nov 15, 2003 (gmt 0)

10+ Year Member



Hey, i think this should do it.

if (file_exists($xmlloc)){
$data = implode('', file($xmlloc));
}
else {
echo "The file does not exist";
}

Glacai

3:08 pm on Nov 15, 2003 (gmt 0)

10+ Year Member



Could also check the fopen

if($fp = fopen($xmlloc,'r'))
{
while(!feof($fp)){
$data = $data . fread($fp, 1024);
}
}
else

dcrombie

4:34 pm on Nov 15, 2003 (gmt 0)



while ($fp &&!feof($fp)) {
$data = $data . fread($fp, 1024);
}

globay

2:17 pm on Nov 16, 2003 (gmt 0)

10+ Year Member



thank you for your replies, I am going to test the versions, and i will report back, soon!