Weeks ago, I was hired by my long time client to fix the WordPress Fatal error: Allowed Memory Size of X Bytes Exhausted of her website which I was built years ago. This failure prevents her from accessing the administration page of her site.
The problem started when the hosting provider noticed an increase in website’s memory usage. To cope with this spike, they increased the memory limits and advise her to install the SuperCache plugin to lessen the server load time. These changes momentarily resolved some of the problems, but the site’s administration page became inaccessible. It reported the WordPress Fatal error: Allowed Memory Size of X Bytes Exhausted. The issue also effectively disables the plugins.
When I looked at the configuration of the website, I noticed that the hosting support increased the memory limit up to 1064MB. Unusually big allocation for a blog! I thought that this is not just a simple memory shortage. There must be other reason that is causing the WordPress Fatal error: Allowed Memory Size of X Bytes Exhausted.
Let us explore what is the meaning of WordPress Fatal error: Allowed Memory Size of X Bytes Exhausted.
This error is reported by PHP when a PHP file is processing too much load than the set limit. The file full path and filename is included in the notification along with the filename.
The full message is shown in the image below which is pointing the option.php as the source of the error.
Normally, the WordPress memory allocation is up to 40MB. When this all used up, the Fatal error: Allowed Memory Size of xxxx Bytes Exhausted will be generated. The easy solution is to increase the memory limits when can be done in multiple ways. This discussion – http://wordpress.org/support/topic/fatal-error-allowed-memory-size-of-33554432-bytes-exhausted-2 – provide a hint on how to resolve this kind of issue.
These are the ways of increasing the memory allocation of your website. You just need to chose one that is easy to implement.
1. Try adding this line to your wp-config.php file:
2. If you have access to your PHP.ini file, change the line in PHP.ini
If your line shows 32M try 64M:
memory_limit = 64M ; Maximum amount of memory a script may consume (64MB)
3. If you don’t have access to PHP.ini try adding this to an .htaccess file:
php_value memory_limit 64M
4. Talk to your host.
The 64MB limit is not absolute. You can increase to any value you want depending on your needs.
Analysis of the Issue
Increasing the memory allocation is good, but, like the problem of a leaking pail, we are trying to resolve the problem by adding more water in it to replace the lost ones, instead of plugging the holes that is causing the leak.
So how do we plug the hole? Because the error specifically point out that the problem is in the memory, it is easy to interpret that the memory was overwhelmed by the size of data that need to be processed. It is worth to check the table that directly linked to the PHP file that is producing an error.
In my case, the file is option.php so it is easy for me to identify its related table, which is wp_options (If the file reported by your error is different then you might need to investigate deeper).
According to the WordPress Codex, wp_options is the table where the WordPress store various preferences and configuration settings. Aside that, the table is also used for storing transient entries. Transient entries are very similar to the option entries except that it has expiration date. In other word, a temporary data.
Now this is the problem. Sometimes a transient entry is very large, and even though there is a expiry date it will not always get deleted by WordPress. One large transient entry is acceptable, but overtime, as WordPress failed to delete some of the temporary entries, it will accumulate. It will eventually arrive to the point when your website settings will remind you that your blog is over capacity, through the WordPress Fatal error: Allowed Memory Size of X Bytes Exhausted notification.
The solution is simple. Delete the transient entries. This is a perfectly safe action because transient records is temporary anyway.
Use the SQL line below will delete all the transient entries. You can use it exactly as it is in your PHPMyAdmin SQL editor of the CPanel.
DELETE FROM 'wp_options' WHERE 'option_name' LIKE ('%_transient_%')
And I strongly advise that you backup all your records. The SQL command is perfectly safe but it better to be prepared if anything goes wrong.
Let me know you thoughts.