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

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).

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 256000000

Both php.ini and .htaccess files should be created in plain text (for example with Notepad on Windows, or TextEdit in Plain Text mode on a Mac) to avoid any formatting information being saved. Rich text editors such as WordPad, MS Word, and TextEdit in its default Rich Text mode will produce unreadable files.

  • 84 Users Found This Useful
Was this answer helpful?

Related Articles

When I try and view my website I get an HTTP Error 403 - Forbidden message.

A '403 Forbidden' message means that the browser has requested a page that it is not permitted to...

My CGI/ASP/PHP script is giving an error when trying to write to a file.

This applies to Linux hosting accounts only.This is almost certainly down to incorrect...

A custom filetype isn't being recognised, how can I make sure it is?

You can force this through using a '.htaccess' file. Remember that the directives inside an...

My CGI/Perl scripts are failing with error 500 (Internal Server Error)

These errors are nearly always related to a coding error within the script, or bad variables...

I can't see the images on my website. Why?

There are several possible reasons why your images are not showing up on your pages as...