Fatal Error: Allowed Memory Size of 134217728 Bytes Exhausted (CodeIgniter + XML-RPC)

前端 未结 29 2327
天涯浪人
天涯浪人 2020-11-21 22:57

I have a bunch of client point of sale (POS) systems that periodically send new sales data to one centralized database, which stores the data into one big database for repor

相关标签:
29条回答
  • 2020-11-21 23:43

    If you're running a WHM-powered VPS (virtual private server) you may find that you do not have permissions to edit PHP.INI directly; the system must do it. In the WHM host control panel, go to Service ConfigurationPHP Configuration Editor and modify memory_limit:

    Updating memory_limit on WHM 11.48.4

    0 讨论(0)
  • 2020-11-21 23:44

    Just add a ini_set('memory_limit', '-1'); line at the top of your web page.

    And you can set your memory as per your need in the place of -1, to 16M, etc..

    0 讨论(0)
  • 2020-11-21 23:47

    ini_set('memory_limit', '-1'); overrides the default PHP memory limit.

    0 讨论(0)
  • 2020-11-21 23:47

    For those who are scratching their heads to find out why on earth this little function should cause a memory leak, sometimes by a little mistake, a function starts recursively call itself for ever.

    For example, a proxy class that has the same name for a function of the object that is going to proxy it.

    class Proxy {
    
        private $actualObject;
    
        public function doSomething() {
    
            return $this->actualObjec->doSomething();
        }
    }
    

    Sometimes you may forget to bring that little actualObjec member and because the proxy actually has that doSomething method, PHP wouldn't give you any error and for a large class, it could be hidden from the eyes for a couple of minutes to find out why it is leaking the memory.

    0 讨论(0)
  • 2020-11-21 23:48

    The most common cause of this error message for me is omitting the "++" operator from a PHP "for" statement. This causes the loop to continue forever, no matter how much memory you allow to be used. It is a simple syntax error, yet is difficult for the compiler or runtime system to detect. It is easy for us to correct if we think to look for it!

    But suppose you want a general procedure for stopping such a loop early and reporting the error? You can simply instrument each of your loops (or at least the innermost loops) as discussed below.

    In some cases such as recursion inside exceptions, set_time_limit fails, and the browser keeps trying to load the PHP output, either with an infinite loop or with the fatal error message which is the topic of this question.

    By reducing the allowed allocation size near the beginning of your code you might be able to prevent the fatal error, as discussed in the other answers.

    Then you may be left with a program that terminates, but is still difficult to debug.

    Whether or not your program terminates, instrument your code by inserting BreakLoop() calls inside your program to gain control and find out what loop or recursion in your program is causing the problem.

    The definition of BreakLoop is as follows:

    function BreakLoop($MaxRepetitions=500,$LoopSite="unspecified")
        {
        static $Sites=[];
        if (!@$Sites[$LoopSite] || !$MaxRepetitions)
            $Sites[$LoopSite]=['n'=>0, 'if'=>0];
        if (!$MaxRepetitions)
            return;
        if (++$Sites[$LoopSite]['n'] >= $MaxRepetitions)
            {
            $S=debug_backtrace(); // array_reverse
            $info=$S[0];
            $File=$info['file'];
            $Line=$info['line'];
            exit("*** Loop for site $LoopSite was interrupted after $MaxRepetitions repetitions. In file $File at line $Line.");
            }
        } // BreakLoop
    

    The $LoopSite argument can be the name of a function in your code. It isn't really necessary, since the error message you will get will point you to the line containing the BreakLoop() call.

    0 讨论(0)
提交回复
热议问题