WordPress uses memory. Plugins and themes use memory. New versions of software may use more memory than before. When that happens and PHP on your server doesn’t have enough memory then PHP will stop with a fatal error like this:
Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 1203208 bytes) in /home/*****/public_html/wp-admin/includes/class-pclzip.php on line 4215
This happens quite a bit but it’s not a bug in WordPress or your new plugin or theme, you simply need to let PHP use more memory on your server. Thankfully WordPress makes it easy to do this. You must define a constant, WP_MEMORY_LIMIT in your server’s wp-config.php like this:
The error message will give you an idea of how much memory is required. The error message says it tried to allocate 1203208 bytes or just over 1MB of memory. The limit here is 67108864 bytes, or 65536KB which is 64MB so here I’d need a WP_MEMORY_LIMIT of more than 66M. The error message will go away once PHP has enough memory but be sure to test it.
If you allocate too much memory your server could start eating into disk swap space. Also be aware that each Apache child process is allowed to use that much memory so if you had ten processes it could use ten times the memory limit in a worst case scenario. If that happens you’ll need more RAM or you’ll have to figure out what’s using so much memory.
There’s also a WP_MAX_MEMORY_LIMIT constant. By default it’s 256M and it’s currently only used when uploading images.
On the off chance that you don’t have WordPress installed and you came here from a search engine, then you’ll want to use ini_set() somewhere early in the PHP process to increase the memory limit:
Finally, I love that the wp-config.php codex page is the first result of a search for WP_MEMORY_LIMIT.
10 thoughts on “Fatal error: Allowed memory size of 67108864 bytes exhausted”
Thanks for the article- I was just thinking about this subject as one of my websites consistantly goes over the allowed memory usage with the memory usage maxed out at 128mb.
Are there any plugins or other tools you could suggest to help diagnose which plug-ins are the most memory intensive?
The simplest way is to go through each of your plugins disabling them one by one until the memory usage goes down, but if you have the RAM it’s worth allocating the memory. You could also dive into the plugin code and use memory_get_usage() but that’s only useful if you’re going to fix the plugin causing the problems and don’t have the extra RAM required.
Where do I enter this code: define(‘WP_MEMORY_LIMIT’, ’128M’);
It goes in your wp-config.php, that’s usually in the same place you installed WordPress.
You can also use this method by putting this in to your .htaccess file:
php_value memory_limit 100M
It works the same way. But it is still nice to have that option to be put in the
Thanks! This worked for me 🙂
It’s not quite that simple. One of my sites kept giving me the same error message even after my web host had upped the limit and I’d raised the limit in pretty every way possible on the site.
And this happened even after I disabled pretty much all the plugins (running more than 3-4 blew it out of the water). Interestingly, the problem seemed to get worse over time.
Ultimately, I exported the content (a sizable database), did a fresh install and reimported the database, images, etc.
Everything worked fine, and I can run a couple dozen plugins without activating the error message.
In other words, something got broken and even installing fresh WP files over the old ones didn’t fix it.
If you open your cpanel and wp-admin ,then use the code editor function to read the error_log to see exactly where the memory went.It will even give you the “line” in the php file that is causing the fatal error. However,since most such fatal errors are inconsistent ,a combination of other memory hogs may have triggered an error in that line. One such memory hog is a Google+ plugin and another may be the loading of sprites or ad images that are not served from a CDN nor from a Google server.
This code isn’t in wp-config.php since version 3.0 i think.
Thank you VERY MUCH! Its worked! =)))