我的情况是这样的,我有处理大量结果集的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