Why does my PHP script fail with 'Fatal error: Allowed memory size of xxxxxx bytes exhausted' Print

  • 8

PHP has a built-in limit on the amount of memory it will allocate. If that limit is reached, the process will exit with this error message. This is usually the result of the PHP script trying to load a large file, such as an image, into memory all at once.

While it is better if you can arrange for the script not to do such things, it is also possible to increase the memory limit to avoid this problem. To do that, edit (or create in your script's folder if it does not exist) the php.ini file with your PHP scripts (create it if it does not exist) and add the following line:

memory_limit=16M

You should replace the '16' with whatever value is appropriate. The default is 8M (8 megabytes, the 8388608 bytes from the error message).  Please note the maximum allowed is 32mb.

If this does not resolve the problem, you can also increase the web server memory limit by editing (or creating in your script's folder if it does not exist) the ".htaccess" file and adding the following line:

RLimitMem 128000000



Was this answer helpful?

« Back