Reading a File - Not Enough Memory
Posted: Tue Apr 13, 2004 10:24 am
Hello:
I'm trying to read in a rather large tab-delimited file, it's almost 8mb. I get an error while reading the file, I'm assuming that it's because it runs out of memory.
The error is: Fatal error: Allowed memory size of 8388608 bytes exhausted at (null):0 (tried to allocate 74 bytes)
The code that I wrote to read this file is:
Does anyone have another way of reading this file in that would work?
Ideally I'd like to open the file and get "one line at a time", but I don't know how to do that. I find it weird to work with this method of reading in "x" bytes at a time from the file, because, how do you know the length of each line?
Thanks,
Peter.
I'm trying to read in a rather large tab-delimited file, it's almost 8mb. I get an error while reading the file, I'm assuming that it's because it runs out of memory.
The error is: Fatal error: Allowed memory size of 8388608 bytes exhausted at (null):0 (tried to allocate 74 bytes)
The code that I wrote to read this file is:
Code: Select all
<?php
$newdata = fopen("/home/www/auser/data/datafile.txt", "r");
while(!feof($newdata)) {
$filedata .= fgets($newdata, 1024);
}
fclose($newdata);
$filelines = explode("\n", $filedata);
?>Ideally I'd like to open the file and get "one line at a time", but I don't know how to do that. I find it weird to work with this method of reading in "x" bytes at a time from the file, because, how do you know the length of each line?
Thanks,
Peter.