用PHP 5GB FILE

时间:2016-01-11 10:32:24

标签: php

你好我需要读取一个5GB的大文件,我得到这样的错误,致命错误:内存不足(分配786432)(试图分配5805810472字节)

<?php 
set_time_limit(0);
ini_set('memory_limit','-1');

$tel = file_get_contents('result.txt');
preg_match_all('/\"telScheme\":\"(.*?)\"/s',$tel,$tels);

$out = fopen("phone.txt","a");
foreach($tels[0] as $fin){
$fin = str_replace('"', '', $fin);
fwrite($out,"$fin\n");
}
fclose($out);

?> 

1 个答案:

答案 0 :(得分:0)

正确的主题结束

<?php 
set_time_limit(0);
ini_set('memory_limit','-1');


$handle = @fopen("result.txt", "r");
$out = fopen("phone.txt","a");

if ($handle) {
    while (($buffer = fgets($handle, 4096)) !== false) {
    preg_match_all('/\"telScheme\":\"(.*?)\"/s',$buffer,$tels);

    foreach($tels[0] as $fin){
    $fin = str_replace('"', '', $fin);
    fwrite($out,"$fin\n");
    }

    }
    fclose($handle);
}

fclose($out);

?>