$files = explode(',',$item);
foreach($files as $files)
{
$handle = file($files);
foreach($handle as $key=>$a_content) {
list($uid, $_tmp1, $_tmp2, $_tmp3, $_tmp4) = explode(":",($handle[$key]));
$this->EmailErrLogService->AddEmailErrLog(array('uid'=>$uid,'error'=>$_tmp1.':'.$_tmp2.':'.$_tmp3.':'.$_tmp4));
}
}是AJAX提交文件路径,比如读出10个文件。循环查询10个文件的信息,然后一个个的入库。大概入了3W条数据就报错了,求解决!Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allo用file打开文件是否要关闭?这影响效率了吗?
应根据出错行的代码来判定是什么性质的问题
while(!feof($handle)) {
$data = explode(":",(fgets($handle)));
$this->EmailErrLogService->AddEmailErrLog(array('uid'=>$data[0],'error'=>$data[1].':'.$data[2].':'.$data[3].':'.$data[4]));
}
fclose($handle);
????这不在减少吗?才 1M
ini_set('memory_limit', '1000M');
这样是 1G 不能在大了,无论你有多少内存条,也不能都给一个进程使用吧?请贴出完整的错误信息,并告知出错行的代码
<head><title>502 Bad Gateway</title></head>
<body bgcolor="white">
<center><h1>502 Bad Gateway</h1></center>
<hr><center>nginx/1.0.14</center>
</body>
</html>
AJAX直接返回这个了
插入了5.7W条数据
是网管丢失。也就是说你的程序已经出现了严重的错误恢复到你开始发帖时的代码,然后重新来过
楼上有几位提到的方法,都是常规有效地。但不一定对你有效
你需要找到你的瓶颈在哪里才行
$handle = file($files);
foreach($handle as $key=>$item) {
list($uid, $_tmp1, $_tmp2, $_tmp3, $_tmp4) = explode(":",($handle[$key]));
if($this->EmailErrLogService->GetEmailErrLog($uid)){}else{
$this->EmailErrLogService->AddEmailErrLog(array('uid'=>$uid,'error'=>$_tmp1.':'.$_tmp2.':'.$_tmp3.':'.$_tmp4));
}
}我就在插入的时候做了个过滤。。重复的就不插入了。结果就502
这个度,只有你自己把握了我期望看到原始的 php 错误信息,那才是解决问题的关键
http://www.cnblogs.com/Zjmainstay/archive/2012/07/15/php_loadTxtDataIntoDatabase.html
$handle = fopen($files, "r");
if ($handle) {
while (!feof($handle)) {
$buffer = fgets($handle);
}
fclose($handle);
}
注意:
不要把整个文件全读