Click to See Complete Forum and Search --> : Limits on size of textfile opened?


xvszero
08-13-2007, 12:00 PM
I have this...

$file = "FA_ccccCUST.txt";
$fp = fopen($file, "r") or die("bang, you're dead!");
$data = fread($fp, filesize($file));
fclose($fp);

And it seems to work on smaller files, but larger files (180 MB for instance) have problems. The PHP page won't even seem to do anything, it isn't even loading, it just... stops, but without displaying the die message either.

Anyone have any ideas?

xvszero
08-13-2007, 12:14 PM
Actually on paring it down a bit this seems to be the line that is getting it f-ed up...

$data = fread($fp, filesize($file));

Maybe the file is too big for a PHP variable?

If so though, I'm not sure exactly how to do this. I guess I could do it line by line somehow?

MykeXero
08-13-2007, 01:03 PM
I know on many ISPs that limit is set to 8MB or so.

If this your own build of php or an isp?

Maximus9999
08-13-2007, 01:49 PM
yup, fread() can only read max 8mb.

http://ca3.php.net/fread

MrCoder
08-13-2007, 01:56 PM
yup, fread() can only read max 8mb.

http://ca3.php.net/fread


That does not sound right to me?

Do you have error reporting enabled?

Have you tried disabling the script time-out?

xvszero
08-13-2007, 02:12 PM
This is PHP running off our server here, I could get them to reconfigure stuff if need be.

Even if the fread could handle more though, could the PHP $data variable store a 180 MB string?!!!

I'm pretty sure I'm going to have to do it line by line for one reason or another...

Maximus9999
08-13-2007, 02:34 PM
Yeah, was thinkin the same. 180mb is a lot of text :)

xvszero
08-13-2007, 03:00 PM
Well even doing it line by line it tanks out when trying to put the 1072nd record into the mysql database. The record seems fine to me so not sure why it wouldn't be able to put it in there...

xvszero
08-13-2007, 03:07 PM
Oh I see, it wouldn't take the ' in this ladies last name.

Hmm.