mmm
mmm

Reputation: 1

How to read 11mb textfile in php?

I read 11mb textfile with php:

$data_array = array();

$counter = 0;        

while(!feof($fh))  {

    $buffer = fgets($fh, 4096);

    $data_array[$counter] = $buffer;

    $counter++;
}

Then I want to use implode function to get all into one variable.

$data = implode("",$data_array); 

But the script does nothing. If I try to store data into one variable during the loop, it takes very long time.
Is there some other way how to do this? I need to have data from 11mb textfile in one variable in php.

Upvotes: 0

Views: 132

Answers (3)

Risto Novik
Risto Novik

Reputation: 8295

You should try to make the text file smaller parts if you can. Also there's execution limit in php.ini file 30 seconds should be default after which the script is terminated.

Upvotes: 0

Billy Moon
Billy Moon

Reputation: 58531

have you tried $data = file_get_contents('filename');?

Upvotes: 0

vartec
vartec

Reputation: 134601

First of all, you're trying to reinvent the wheel. There is already function in PHP for that:

$data = file_get_contents($filename) 

Second, if you're not getting any results, check the memory and time limits you have set in php.ini.

Upvotes: 9

Related Questions