0
你好,我需要閱讀5GB的大文件,我得到這樣的錯誤,致命錯誤:內存(分配的786432個)(試圖分配5805810472個字節)在PHP 5GB文件中讀取大文件
<?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);
?>
你告訴PHP讀取大型文件5GB到內存中,並得到一個「內存不足」的錯誤.....你是怎麼想到....嘗試閱讀一次行,所以你一次只能在內存中有一行數據 –
我需要一個副本到我的代碼 – Brucea
所以你想要我爲你寫代碼?沒有!但我會指出你[fopen()](http://www.php.net/manual/en/function.fopen.php),[fgets()](http://www.php.net/ manual/en/function.fgets.php)和[fclose()](http://www.php.net/manual/en/function.fclose.php) –