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

前端 未结 29 2325
天涯浪人
天涯浪人 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:27

    In my case it was a brief issue with the way a function was written. A memory leak can be caused by assigning a new value to a function's input variable, e.g.:

    /**
    * Memory leak function that illustrates unintentional bad code
    * @param $variable - input function that will be assigned a new value
    * @return null
    **/
    function doSomehting($variable){
        $variable = 'set value';
        // Or
        $variable .= 'set value';
    }
    
    0 讨论(0)
  • 2020-11-21 23:28

    I kept getting this error, even with memory_limit set in php.ini, and the value reading out correctly with phpinfo().

    By changing it from this:

    memory_limit=4G
    

    To this:

    memory_limit=4096M
    

    This rectified the problem in PHP 7.

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

    When you see the above error - especially if the (tried to allocate __ bytes) is a low value, that could be an indicator of an infinite loop, like a function that calls itself with no way out:

    function exhaustYourBytes()
    {
        return exhaustYourBytes();
    }
    
    0 讨论(0)
  • 2020-11-21 23:29

    It's very easy to get memory leaks in a PHP script - especially if you use abstraction, such as an ORM. Try using Xdebug to profile your script and find out where all that memory went.

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

    For Drupal users, this Chris Lane's answer of:

    ini_set('memory_limit', '-1');
    

    works but we need to put it just after the opening

    <?php
    

    tag in the index.php file in your site's root directory.

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

    Changing the memory_limit by ini_set('memory_limit', '-1'); is not a proper solution. Please don't do that.

    Your PHP code may have a memory leak somewhere and you are telling the server to just use all the memory that it wants. You wouldn't have fixed the problem at all. If you monitor your server, you will see that it is now probably using up most of the RAM and even swapping to disk.

    You should probably try to track down the offending code in your code and fix it.

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