Page 1 of 1

fopen and "slow" probllem

Posted: Tue Jan 06, 2004 2:06 am
by pelegk2
i have this code :

Code: Select all

<?php
$handle = fopen ("http://www.bankisrael.gov.il/eng.shearim/index.php", "rb");
$contents = "";
while (!feof($handle)) {
    $data = fread ($handle, 1024);
    $contents .= $data;
	//echo $contents;
}
fclose ($handle);
?>
when i tried to use it yesterdya for some reason i thonk there was a problem on the web site i was reading the page
beacuse of that in some point the apache.exe gave me FATAl error!!!!!
and the apache has crashed!
how can i prevent it?
thanks in advance
peleg

Posted: Tue Jan 06, 2004 2:01 pm
by xisle
just

Code: Select all

echo $data;
to output each line of the file.
By appending to the $contents you are reprinting everything up to that line on each line, thus overflowing.

your script is doing something like this...

Code: Select all

echo line1 text;

echo line1 text;
echo line2 text;

echo line1 text;
echo line2 text;
echo line3 text;

echo line1 text;
echo line2 text;
echo line3 text;
echo line4 text;
if you want the entire file in one string than do this...

Code: Select all

$data=file($filename);
$outputstring=implode($data, "");

Posted: Wed Jan 07, 2004 1:03 am
by pelegk2
with $data i just read line by line the file!

Posted: Wed Jan 07, 2004 4:13 pm
by xisle
nO sh!T !! :LOL: