If you are working on PHP, then definitely you are familiar with Fatal Error Allowed memory size exhausted. This error occurs when your PHP script exceeds the default memory allocated for execution. Due to which your scripts stop working and shows the error message that allowed memory size exhausted.
To know the default memory allocated for execution, you can check the memory limit in your php.ini file.
php.ini file path on Ubuntu.
1 |
/etc/php5/apache2/php.ini |
open your php.ini file
1 |
vi /etc/php5/apache2/php.ini |
and search for memory_limit. Check how much memory is allocated, you can increase this memory limit to get rid of this error message.
How to avoid PHP script running out of memory
In my case, I have allocated 128 MB. You can allocate as per your need.
NOTE: If you make any changes in php.ini file, you need to restart the apache webserver.
If you don’t want to edit php.ini file you can allocate memory limit in your php file as well.
1 2 3 |
// To allow unlimited memory size. ini_set('memory_limit', '-1'); |
1 2 3 |
// To allocate 512 M memory ini_set('memory_limit','512M'); |
Fatal error: Allowed memory size Exhausted Error in WordPress
There are numerous cases where people, complain them that when they try to install and activate new plugin the error comes.
Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 7680 bytes)
The simple solution of this problem is Open your wp-config.php file and include the following line
1 2 3 |
define('WP_MEMORY_LIMIT', '128M'); // Here i am allocating 128 MB you can do that as per your need. |
In case your host does not allow increasing memory limit in that way. Then it will not work. Contact your host they might increase memory limit through php.ini file.