开发者

How to read 11mb textfile in php?

开发者 https://www.devze.com 2023-02-22 02:53 出处:网络
I read 11mb textfile with php: $data_array = array(); $counter = 0; while(!feof($fh)){ $buffer = fgets($fh, 4096);

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 ve开发者_C百科ry long time.

Is there some other way how to do this? I need to have data from 11mb textfile in one variable in php.


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.


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号