fopen and "slow" probllem

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
User avatar
pelegk2
Forum Regular
Posts: 633
Joined: Thu Nov 27, 2003 5:02 am
Location: Israel - the best place to live in after heaven
Contact:

fopen and "slow" probllem

Post 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
User avatar
xisle
Forum Contributor
Posts: 249
Joined: Wed Jun 25, 2003 1:53 pm

Post 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, "");
User avatar
pelegk2
Forum Regular
Posts: 633
Joined: Thu Nov 27, 2003 5:02 am
Location: Israel - the best place to live in after heaven
Contact:

Post by pelegk2 »

with $data i just read line by line the file!
User avatar
xisle
Forum Contributor
Posts: 249
Joined: Wed Jun 25, 2003 1:53 pm

Post by xisle »

nO sh!T !! :LOL:
Post Reply