$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打开文件是否要关闭?这影响效率了吗?

解决方案 »

  1.   

     ini_set('memory_limit', '改成合适的值');  //脚本中加上这句试试
      

  2.   

    不要用file一次读取文件所有内容,可以用stream_get_line读一行处理一行
      

  3.   

    Fatal error: Allowed memory size of ... 错误信息中是有行号的
    应根据出错行的代码来判定是什么性质的问题
      

  4.   

    请问这个咋弄? 我已经换成行读了。$handle = fopen($files,'r');
                            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);
      

  5.   

    ini_set('memory_limit', '1000000');
    ????这不在减少吗?才 1M
    ini_set('memory_limit', '1000M');
    这样是 1G 不能在大了,无论你有多少内存条,也不能都给一个进程使用吧?请贴出完整的错误信息,并告知出错行的代码
      

  6.   

    <html>
    <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条数据
      

  7.   

    Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allo..补齐后面的信息
      

  8.   

    现在插入直接返回  502 Bad Gateway
      

  9.   

    502 Bad Gateway
    是网管丢失。也就是说你的程序已经出现了严重的错误恢复到你开始发帖时的代码,然后重新来过
    楼上有几位提到的方法,都是常规有效地。但不一定对你有效
    你需要找到你的瓶颈在哪里才行
      

  10.   


     $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
      

  11.   

    我们又不知道你的那些方法都做了些什么?要求传入写什么样的参数?
    这个度,只有你自己把握了我期望看到原始的 php 错误信息,那才是解决问题的关键
      

  12.   

    做个sh文件free -m | grep -i mem | awk '{if($4 < 512){ print("3") > "/pro/sys/vm/drop_caches"}}';crontab 每5分钟执行一次,清除一下内存。php文件set_time_limit(0);
      

  13.   

    试试我这个。
    http://www.cnblogs.com/Zjmainstay/archive/2012/07/15/php_loadTxtDataIntoDatabase.html
      

  14.   

    解决方法:
    $handle = fopen($files, "r");
    if ($handle) {
        while (!feof($handle)) {
            $buffer = fgets($handle);
        }
        fclose($handle);
    }
    注意:
    不要把整个文件全读