PHP Fatal error allowed memory size exhausted

前端 未结 5 541
故里飘歌
故里飘歌 2021-01-19 21:21

I\'m writing a codeigniter application, upon doing a query i get hit with the following fatal error.

Fatal error: Allowed memory size of 134217728 byt

相关标签:
5条回答
  • 2021-01-19 21:38

    If anybody else has this problem:

    Make sure your memory size in php.ini has an M after the number.

    I had 512 in there....when I changed it to 512M .....no more problem.

    z

    0 讨论(0)
  • 2021-01-19 21:39

    Your code looks fine. Check if some function is getting called repeatedly.

    You could use

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

    as a temporary solution. or just increase the memory_limit

    Chceck you php.ini file. If it is in the below form,

    memory_limit=8G
    

    Change that in the form of MB

    memory_limit=8192M
    

    You can also do it in your code like

    ini_set('memory_limit', '8192M'); 
    
    0 讨论(0)
  • 2021-01-19 21:41

    The problem occurs because a private method kept calling itself over and over again until the allocated memory is exhausted and the script stops execution

    private function get_member_data($tid){
        return $this->get_member_data($tid);
    }
    

    This is a stupid human error, the above method should have been re-written as below

    private function get_member_data($tid){
    //Call to model method
        return $this->invest->get_member_data($tid);
    }
    

    Sorry, and thanks everyone.

    0 讨论(0)
  • 2021-01-19 21:48

    If you want to know where the memory goes you should look into PHP memory profiling: PHP memory profiling

    Personally I would just increase the PHP max_memory to 256MB and see if it's enough ;)

    0 讨论(0)
  • 2021-01-19 22:01

    Put this line on your codeigniter's index.php. So it will be affected for whole project.

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

    Note: This is just a quick fix. This bug has not been resolved in php itself.

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