How to Increase PHP Memory and Fix the WordPress Memory Exhausted Error
Any website built on WordPress requires memory to run properly; however, there is a set limit to the memory that is allocated to each site. When you exceed this limit you will either see this dreaded error message:
fatal error: allowed memory size of 67108864 bytes exhausted
Or worse! If you’re one of the really unlucky ones, you might even be greeted with the infamous White Screen of Death.
If your site doesn’t function properly and all you can see is a white screen, it is a real possibility that WordPress is running out of memory and certainly worth checking.
Don’t fear! There are a few ways that you can fix this issue and get your website back up and running. If you haven’t encountered this error yet, this post will hopefully help you to avoid it in the future or know what to do when it happens.
What Causes Memory Exhaustion in WordPress?
PHP is the programming language that powers all WordPress sites. Parts of PHP code, called scripts, use memory when they run and setting a limit on the memory they use is a necessary precaution to protect servers – the computer or computers where the files for your website, and often many other websites, are stored.
If one of the PHP scripts on your WordPress site is poorly written or has a mistake it can run wild and consume an enormous amount of memory.
It could even not only crash your website, but consume all the memory of the entire server and crash every other website or application that is running on that server.
By setting a default limit to the memory taken up by PHP scripts for each website, WordPress prevents this from happening.
Fixing the Memory Exhaustion Error
There are a couple of methods you can apply to fix the memory exhaustion error:
- you can increase the WordPress memory limit on your account
- or you can get rid of the PHP script that is causing the error.
Here’s a beginners guide on how to do both these things:
Increase PHP Memory Limit in WordPress – the Easy Fix
As the error clearly indicates that you have run out of memory, it stands to reason that a good fix could be to simply increase the amount of memory that WordPress has allocated – overriding the set limit. This is entirely possible and not that difficult to implement.
The usual limit for memory allocated by WordPress id 64mb. WordPress can allocate more but you have to do a little bit of manual work in order for it to do so.
This is done by editing the wp-config file. First, you have to download all your WordPress files via FTP.
Connecting Your WordPress Site to Your Computer With FTP
Using an FTP client, such as FileZilla, you can download all your WordPress files to your machine, edit them using a text editor, then upload the amended files back to your WordPress account. Check out this guide on how to choose the best WordPress FTP client for your site.
Editing the wp-config File and Increasing the Memory Limit
When connected, your site’s folders and files will be uploaded to your computer. Look for the folder containing all your WordPress files and open the wp-config file. Locate this line of code:
(define ‘WP_MEMORY_LIMIT’, ‘64M’ );
And change it to:
(define ‘WP_MEMORY_LIMIT’, ‘256M’ );
If you can’t find the original line of code, and your file definitely doesn’t have it in there, simply add the new line fresh to the file. This will bump your memory limit up and stop WordPress from thinking that you’ve run out of memory.
Identifying the Source of Memory Exhaustion
An alternative is to fix the actual script that is causing the error. If your WordPress memory limit is already at the maximum 256M, or the above fix doesn’t work, you might have a little bit more work in identifying the source of the problem and getting rid of it.
When you receive the fatal memory error, you can almost always trace the problem to a plugin or, in some cases, a theme that you are running. It is unlikely that your core WordPress scripts would need more than the allocated memory to run.
There are a few different ways to diagnose which plugin is causing the issue and there are many plugins available that can show you memory consumption.
Diagnoses can also be done through your hosting provider by downloading PHP files from cPanel, or a similar program, and manually checking the memory.
If you’ve recently downloaded a plugin, around about the same time the error began, try turning off the plugin and see if the issue resolves itself. If that doesn’t work, try going through the plugins and turning them off one by one.
Once you’ve identified the plugin causing the problem you should consider if you really want to continue using it or maybe look for an alternative that doesn’t take up so much memory.
WordPress Memory and Caching solutions
When you’re running low on memory your website might also appear to be running slowly to end users, causing a bad user experience.
This is sometimes caused by bad PHP scripts but is more often caused by large image or video files.
Caching help can solve this problem by storing parts of your website in users’ browsers, so when they visit your site again, they don’t have to load all the data to make your website work – only a selected few parts.
Memory and SEO
Websites which load slowly aren’t just bad for users, they’re also bad for Search Engine Optimization (SEO) as Google, and the other major search engines, by far prefer to present fast-loading websites.
An experienced SEO can help you to fix the slow loading issue. For example, at the SEOniverse website optimization I often help customers limit the memory use of the files on their WordPress site and boost search engine rankings as a result.
A good SEO company can also tidy up any errant scripts and optimize the plugins that you are running making using WordPress a better experience for both the end user and you as you are editing.