php内存限制2000M耗尽 [英] php memory limit 2000M exhausted

查看:201
本文介绍了php内存限制2000M耗尽的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试将不要调用列表 xml文件上传到MySql DB。文件大小为256MB。它被上传,但是当它开始处理循环电话号码和连接1000个电话号码在一个变量。当它达到1000的限制时,创建一个INSERT查询并执行查询。 BUt的问题是插入3,50,000条记录后说:致命错误:允许内存大小2097152000字节用尽(试图分配24字节)在/ var / domains / htdocs / aim / leads / dnc在行1308)

Am trying to upload Do not call list xml file to MySql DB. The file size is 256MB. It gets uploaded but when its starts processing am looping the phone numbers and concatenating 1000 phone numbers in a variable. When it reaches the limit of 1000, am creating a INSERT query and executing the query. BUt the problem is after inserting 3,50,000 records it say "Fatal error: Allowed memory size of 2097152000 bytes exhausted (tried to allocate 24 bytes) in /var/domains/htdocs/aim/leads/dnc on line 1308)".

以下是程式码片段。

                    if(($fp = fopen($destination,"r"))) {

                        $buffer = fgets($fp);
                        $objXml = new XML($buffer);
                        $lists = Set::reverse($objXml);

                        $buffer = fgets($fp);
                        $objXml = new XML($buffer);
                        $acc = Set::reverse($objXml);

                        try {
                            while(!feof($fp)){
                                $counter = 0;
                                $phonesNo = "";

                                while(!feof($fp) && ($buffer = fgets($fp)) && $counter != 1000){

                                    $objXml = "";
                                    $arrXml = "";

                                    $objXml = new XML($buffer);

                                    $arrXml = Set::reverse($objXml);


                                    $counter++;
                                    if(isset($arrXml['Ph']['val']))
                                        $phonesNo .= "(".$acc['Ac']['val'].$arrXml['Ph']['val']."),";

                                }

                                $phonesNo = substr($phonesNo,0,-1);
                                $sql = "INSERT INTO do_not_call_lists (`phone`) VALUES " .$phonesNo;

                                unset($phonesNo);
                                $this->Lead->query($sql);
                            }
                        }catch (Exception $ex){
                            trigger_error("ERROR: ". $ex->getMessage(). "  Trace: ".$ex->getTrace());
                        }

                        $this->Session->setFlash('File imported successfully.','default',array('class'=>'sucessMsg'));

                     }

提前多谢。

推荐答案

我想他的意思是不是如何扩展的限制,但为什么这是分配2GB的内存?

I think what he means is not how to extend the limits, but why the hell is this allocating 2GB of RAM?

从它的外观,我假设你使用 simplexml 加载数据。 SimpleXML是一个内存过度,它不能用于大文件没有这种情况发生。您应改为尝试使用:

From the looks of it, I'm assuming you're using simplexml to load the data. SimpleXML is a memory overkill and it can't be used for large files without exactly this happening. You should instead try using:


  1. 基于 SAX解析器(比第二个更少的内存使用,但更难操作)

  2. pull基于 XMLReader

  1. event based SAX parser (less memory usage than the 2nd one, but much harder to operate)
  2. pull based XMLReader

FYI,我已经使用SAX加载大约200MB XML文件,峰值内存使用大约5MB,所以是的,内存消耗是无法比较的。

FYI, I've been using SAX to load about 200MB XML file with peak memory usage about 5MB, so yes, the memory consumption is uncomparable.

这篇关于php内存限制2000M耗尽的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆