Home > database >  Memory available bigger than tried error in PHP
Memory available bigger than tried error in PHP

Time:11-02

I am getting these errors repeatedly in my logs

PHP Fatal error:  Allowed memory size of 134217728 bytes exhausted (tried to allocate 20480 bytes)
PHP Fatal error:  Allowed memory size of 134217728 bytes exhausted (tried to allocate 32768 bytes)

I don't get why it would die with memory size being much bigger then the bytes attempted to allocate!!

CodePudding user response:

You can expand your memory from within your file with the following line of code or directly in php.ini and restart server.

ini_set('memory_limit','16M');

change memory_limit in php.ini to higher value which I do not recommend at all - with your approach you will hit this wall once again. you can do following things.

  • Default php.ini memory_limit is 128 MB.
  • Optimize your code to use a normal amount of data
  • Optimize the query by selecting only used fields or use "pagination"

CodePudding user response:

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

overrides the default PHP memory limit.

  • Related