WordPress Allowed Memory Size Exhausted: Read the Byte Count
On this page, 9 sections
“Allowed memory size of N bytes exhausted” means one PHP request used more memory than the memory_limit in force at that moment. The number N is the clue. Convert it to megabytes and it tells you which setting is the ceiling: WordPress, php.ini, or the PHP-FPM pool.
Most guides tell you to paste define('WP_MEMORY_LIMIT', '256M'); into wp-config.php. Sometimes that does nothing, and the reason is in two files of core and one line of the PHP manual.
I read WordPress 7.1.3 source and the PHP manual on 11 October 2026. I did not hit this error on a live site, and I ran nothing on production. The byte conversions were computed in Python.
What the number tells you
PHP prints the limit in bytes. Divide by 1,048,576 to get megabytes. These are the values worth recognising:
41943040is 40M, the WordPress default forWP_MEMORY_LIMITon a single site.67108864is 64M, the same default on multisite.134217728is 128M, the PHP default formemory_limit.268435456is 256M, the usual ceiling WordPress gives the admin area.
If your error shows a number that is none of these, a host or a config file set it. That number is the limit you need to change, not the one in your tutorial.
What WordPress does with the limit
Two pieces of core code decide this. The first is wp_initial_constants() in wp-includes/default-constants.php.
WP_MEMORY_LIMITis 40M on a single site and 64M on multisite. If PHP says the limit cannot be changed, it is set to whatever the current limit is.WP_MAX_MEMORY_LIMITis 256M by default. If the limit cannot be changed, it is the current limit. IfWP_MEMORY_LIMITis higher than 256M, it follows that.- WordPress then calls
ini_set( 'memory_limit', WP_MEMORY_LIMIT )only when the current limit is not -1 andWP_MEMORY_LIMITis -1 or larger than the current limit.
Read that last line again. WordPress raises the limit and never lowers it. On a stock PHP install with a 128M limit, the 40M default is lower, so nothing happens, and your front end runs at 128M. The 40M number is a floor.
The second piece is wp_raise_memory_limit() in wp-includes/functions.php. The admin area and image handling call it. It returns early if the setting cannot be changed or the limit is already -1. Otherwise it raises the limit to WP_MAX_MEMORY_LIMIT when that is larger. Plugins can change the target through the admin_memory_limit and image_memory_limit filters.
So there are usually two different limits on one site: whatever PHP is set to for visitors, and 256M for wp-admin. An error that only happens in wp-admin has a different cause from one on the home page.
Why the constant sometimes does nothing
Everything above depends on one check: is memory_limit changeable at runtime? The PHP manual lists it as changeable in a script. A PHP-FPM pool can lock it. The FPM configuration page says settings defined with php_admin_value and php_admin_flag cannot be overridden with ini_set(), and its example is exactly this setting:
; /etc/php/8.3/fpm/pool.d/www.conf (path varies by distro)
php_admin_value[memory_limit] = 128M
When that line exists, WordPress finds the limit unchangeable, sets WP_MEMORY_LIMIT to the current value, and your define() has no effect. The error keeps printing the same byte count however high you set the constant. The fix is in the pool file, not in wp-config.php.
The developer documentation for wp-config.php says the same from the other side: hosts may not allow you to raise the limit. When the host controls it, ask them to change the pool value.
One more PHP detail. The manual says PHP 8.5.0 adds a max_memory_limit directive. It is set at startup and defaults to -1. A host that sets it caps what any script can raise to, which is another way a constant can be ignored on a new PHP version.
Where to raise it
Work from the outside in. Change the layer that is actually the ceiling.
- Read the byte count in the error and match it to the list above.
- If it is a pool value (
php_admin_value), change it in the pool file and reload PHP-FPM. - Otherwise set
memory_limitinphp.inior your host’s PHP settings. - Last, set the WordPress constants, which only help if the limit is changeable.
define( 'WP_MEMORY_LIMIT', '256M' );
define( 'WP_MAX_MEMORY_LIMIT', '512M' );
WP_MAX_MEMORY_LIMIT is for the admin area. Put both lines above the “stop editing” comment in wp-config.php. wp-config constants that change behaviour explains where that line sits.
Raising the limit is not the fix
A script that needs 400 MB for a normal page is a bug or a bad plugin. Raising the limit hides it until traffic multiplies it. Each PHP worker can use up to the limit, so a higher number multiplies across workers.
Find what spends it. The fatal error names the file and line where PHP ran out, which is the last allocation, not always the cause. Turn on logging and read the stack of files around it:
define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG_DISPLAY', false );
To see how much a request really uses, log the peak at shutdown from a must-use plugin. This is PHP I syntax-checked with php -l but did not run on a site:
<?php
// wp-content/mu-plugins/log-peak-memory.php
register_shutdown_function( function () {
$mb = round( memory_get_peak_usage( true ) / 1048576, 1 );
error_log( ( $_SERVER['REQUEST_URI'] ?? '' ) . ' peak ' . $mb . ' MB' );
} );
Sort the log by peak and look at the top URLs. Then disable plugins one at a time on a copy of the site. Find the plugin slowing your WordPress site has the method. If a single query returns an enormous result set, Finding the slow query in WordPress covers it. Large autoloaded options are another common spender, covered in the options table autoload audit.
How this was checked
I read default-constants.php and functions.php from the WordPress 7.1.3 tag, the PHP core ini and FPM configuration pages, and the wp-config documentation on 11 October 2026. I computed the byte values in Python: 40M is 41,943,040, 64M is 67,108,864, 128M is 134,217,728 and 256M is 268,435,456.
I ran php -l on the PHP snippets. I did not trigger the error, did not test a PHP-FPM pool override, and did not run the mu-plugin. The behaviour with php_admin_value is from the manual and from reading the source, not from a test.
Questions people ask
Is 256M enough for WordPress?
It is the default WordPress targets for the admin area. A site that needs more has something unusual running, and that is worth finding.
Why do I get the error only in wp-admin?
The admin area is raised to WP_MAX_MEMORY_LIMIT, so its ceiling differs from the front end. Check the byte count to see which one you hit.
Does editing wp-config.php need a restart?
No. The file is read on every request. PHP-FPM pool and php.ini changes need a PHP reload.
Do this today
Take the byte count from your last memory error and divide it by 1,048,576. If it matches a pool value, edit the pool file. If not, set memory_limit in php.ini first.
Resources
- WordPress 7.1.3, default-constants.php, wp_initial_constants(), read 11 October 2026
- WordPress 7.1.3, functions.php, wp_raise_memory_limit(), read 11 October 2026
- PHP manual, core php.ini directives (memory_limit), read 11 October 2026
- PHP manual, FPM configuration (php_admin_value), read 11 October 2026
- Editing wp-config.php, WordPress developer documentation, read 11 October 2026