I had a previously working PHP script, but it threw this error message that said: “PHP Fatal error: Allowed memory size of 8388608 bytes exhausted…”. This is something that happens when the memory requirements exceed the default 8MB limit in PHP.
If you’re getting this error message, don’t worry because it’s easy to solve.
If you want to change the memory limit for a specific script, you just need to include a line at the top of the script:
By doing so, you increase the memory limit to 12M (or 12 megabytes, which is 12582912 bytes). If it still gives you the same error, keep increasing the memory limit. You don’t want to give PHP too much because your server has a fixed amount of memory, and giving PHP more memory means an overall decrease in the amount of memory for any other task.
If you have several PHP scripts running on the server that require more memory, or if you don’t know which script file to edit, you can make a site-wide change by adding a line to the serverâ€™s php.ini file:
memory_limit = 12M
You can also create your changes in a .htaccess file and put it in your site’s root. Include these lines:
php_value upload_max_filesize 16M
php_value max_execution_time 200
php_value post_max_size 16M
php_value max_input_time 100
php_value memory_limit 16M
That’s it! You’re all set, and you shouldn’t see the error message anymore 🙂