“Allowed memory size exhausted”
PHP has run out of memory. You can raise the limit in wp-config.php, but also find out what is using all that memory.
- You need
- FTP
- Updated
The message means PHP has used up the memory it may use for one request, and stopped. Page builders and plugins that import data or make backups use a lot of memory. The limit is PHP's memory_limit. Your hosting provider sets it, and WordPress can raise it with WP_MEMORY_LIMIT.
You can raise the limit, but you should also find out what is using the memory. Otherwise the error can come back the next time you install a plugin.
Read the numbers in the error
The message looks something like this:
PHP Fatal error: Allowed memory size of 41943040 bytes exhausted (tried to allocate 20480 bytes) in /wp-content/plugins/example/file.php
The first number is the limit in bytes. Divide it by 1,048,576 to get megabytes. The 41943040 in the example is 40 MB, the WordPress default for a single site. The end of the message shows the file that was running when memory ran out. If it's under wp-content/plugins, the folder name tells you which plugin it is.
If you only see a white page or a critical error, you'll find the message in the error log. See turn on the error log.
Check the limit in wp-admin
If you can get into wp-admin, go to Tools → Site Health and open the Info tab. Under Server you'll find PHP memory limit, the limit that actually applies to the site.
Administrators get more memory in wp-admin, 256 MB by default, than visitors get on the public site. That is why wp-admin can work while the rest of the site fails. Under WordPress Constants you can see WP_MEMORY_LIMIT and WP_MAX_MEMORY_LIMIT.
Turn on the error log
Find the line define( 'WP_DEBUG', false ); in wp-config.php and replace it with these three lines:
define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG_DISPLAY', false );
If the line isn't there, add the three lines just above the line with require_once ABSPATH . 'wp-settings.php';.
Reload the site and open wp-content/debug.log. Set WP_DEBUG back to false and delete debug.log when you're done. Otherwise anyone can read the log in a browser.
Raise the limit in wp-config.php
- Connect with FTP or the file manager in your hosting panel, and make a copy of
wp-config.php. - Add this line just above the line with
require_once ABSPATH . 'wp-settings.php';:
define( 'WP_MEMORY_LIMIT', '256M' );
- Reload the site, and check PHP memory limit in Site Health again.
If it shows a lower number, your host has set a limit that PHP isn't allowed to exceed.
Raise the limit in the hosting panel
Most hosting panels have a page for PHP settings where you can change memory_limit. If you can't find it, your hosting provider can do it for you. If the server runs PHP-FPM, you can also set memory_limit = 256M in a .user.ini file in the root folder. The change takes effect within five minutes. Some hosting plans have a fixed memory ceiling, and then you need a plan with more memory.
Find out what is using the memory
- Look at which plugin the error points to, and whether the error only happens on some pages or when you do something specific, like importing or saving.
- Deactivate that plugin under Plugins, and see if the error goes away.
- If the message points to different plugins each time, deactivate them one by one until the error goes away.
The Query Monitor plugin shows the peak memory use of each page in the admin bar, so you can see which pages are close to the limit.
If one plugin uses far more memory than the rest of the site, you can upgrade to a plan with more memory, or look for a similar plugin that uses fewer resources.
When 256 MB isn't enough
If the site still runs out of memory with the limit at 256 MB or more, raising it further rarely helps. In that case an experienced PHP developer has to go through the code and the architecture to find out what is using all that memory.