Page 1 of 1

Need help in reading text file

Posted: Tue May 25, 2010 11:41 am
by rajsekar2u
Hi,

I have a doubt in reading text file.
I've detailed the issue below.

I need to read a text file of 450MB and need to display a row in it.
Is there any way to reduce the reading time. because its showing me the below error.

Code: Select all

Fatal error: Allowed memory size of 373293056 bytes exhausted (tried to allocate 78 bytes) in E:\xampp\htdocs\projects\test\car\test.php  on line 11

Re: Need help in reading text file

Posted: Tue May 25, 2010 12:02 pm
by Jonah Bron

Code: Select all

function get_line($file, $line_to_read) {
    $file = fopen($file, 'r');
    while ($line_to_read > 0) {
        fgets($file, 0);
        $line_to_read--;
    }
    return fgets($file);
}
echo get_line('file.txt', 42);

Re: Need help in reading text file

Posted: Tue May 25, 2010 12:22 pm
by AbraCadaver
How do you know what row? Is it on a specific line or do you need to search for something in order to find it?

Re: Need help in reading text file

Posted: Tue May 25, 2010 12:25 pm
by lcarron000
I don't know how much memory your server has but, try this ...

Code: Select all

ini_set("memory_limit","500M");