A quick fix for php running out of memory

  • 2020-10-23 20:56:10
  • OfStack

Sometimes when we run the php program again, it comes up

Allowed memory size of 8388608 bytes exhausted (tried to allocate 1298358 bytes)

The reason for this error: in making sure that it is not caused by the program (such as an endless loop), it is because the default maximum memory consumed by php pages is 8M (as seen in ini pieces of PHP),

This error occurs when the file is too large or the image is too large to read.

Solutions:

1. Modify php.ini Change memory_limit from 8M to 16M (or larger), and restart apache service

2. Add ini_set(' memory_limit', '**M') to PHP file; Note: For the normal use of other resources in the system, please do not set memory_limit too large, where -1 is unlimited

php_value memory_limit 16M(or larger)


Related articles: