我的情況是這樣的,我有處理大量結果集的PHP
$data = $somearray; //say the number of records in this array is 200000
IAM循環這個數據,處理一些功能和寫這個數據到Excel中的一個巨大的數據集從MySQL表提取文件
$my_file = 'somefile.csv';
$handle = fopen($my_file, 'w') or die('Cannot open file: ' . $my_file); file
for($i=0;$i<count($data);$i++){
//do something with the data
self::someOtherFunctionalities($data[$i]); //just some function
fwrite($handle, $data[$i]['index']); //here iam writing this data to a file
}
fclose($handle);
我的問題是,循環獲取內存耗盡......它顯示「的致命錯誤,允許內存大小..」反正是有處理這個循環沒有枯竭
由於服務器限制IM無法提高PHP內存限制像
ini_set("memory_limit","2048M");
我不是關注它takes..even的時間,如果它需要hours..so我做set_time_limit(0)
難道你不能在批處理中讀取MySQL數據,還是按行逐行處理,而不是將整個集合保存到變量中? – Prix 2014-09-05 08:30:18
我也嘗試過批處理......但它仍然掛起......有沒有辦法我們可以在每個循環結束時釋放內存 – coolguy 2014-09-05 08:33:34
要釋放內存只需將變量設置爲null,垃圾收集器應該處理記憶。 – 2014-09-05 08:35:29