ERROR · 02 · VERIFIED 2026-10allwpcare.com/errors/allowed-memory-size-exhausted/
Errors / allowed-memory-size-exhausted

Fatal Error: Allowed Memory Size Exhausted

PHP hit its memory limit. The number in the message is the limit in force. Read it, raise WP_MEMORY_LIMIT, and find what used the memory if it returns.

The message you see
1−Fatal error: Allowed memory size of 41943040 bytes exhausted (tried to allocate 62918656 bytes) in /wp-content/plugins/some-plugin/file.php on line 12
Last verified Oct 2026Tested with WordPress 7.1Applies to WordPress 7.1 (tested) · PHP 7.4+

Why it happens

  • The memory limit is too low for what the page does. WordPress raises a lower PHP limit only up to 40 MB on a single site by default, which is tight for a site with several large plugins.
  • A plugin or theme uses far more memory than it should, because of a bug, a very large query or a loop that never ends.
  • A heavy task runs in one request: an import, a backup, a large image upload or resize, a bulk update, or a page builder saving a big page.
  • The host sets the limit in a way WordPress cannot raise, so WP_MEMORY_LIMIT in wp-config.php has no effect.
  • The command-line PHP has a different limit from the web PHP, so a task works in the browser and fails in WP-CLI, or the other way round.

How to fix it

Try the fixes in this order. Each one is independent: stop as soon as the error is gone.

FIX 01

Read the number and the file in the message

  1. The first number is the limit that was in force when PHP stopped. 41943040 bytes is 40 MB. Common values: 33554432 is 32 MB, 67108864 is 64 MB, 134217728 is 128 MB, 268435456 is 256 MB, 536870912 is 512 MB.
  2. The second number is the size of the allocation that failed. A value of tens of megabytes means one operation tried to grab a big block at once, such as loading a huge file or building a very large array.
  3. The path at the end names where it ran out. A path under wp-content/plugins/name/ points at that plugin. It is not always the cause, since it only shows where the last allocation failed.
  4. If the message does not show on the page, it is in the debug log or the host's PHP error log. See the critical error guide for how to turn the log on.
FIX 02

Raise WP_MEMORY_LIMIT

  1. Open wp-config.php in the WordPress root and keep a copy of the original.
  2. Above the line that says to stop editing, add define( 'WP_MEMORY_LIMIT', '256M' );.
  3. With WP-CLI, wp config set WP_MEMORY_LIMIT 256M adds the same line.
  4. Reload the page that failed. On my test site, a task that needed about 60 MB failed at a limit of 40 MB and passed with this line.
  5. Check the value in use at Tools → Site Health → Info → WordPress Constants and Server. The first shows WP_MEMORY_LIMIT and WP_MAX_MEMORY_LIMIT, the second shows PHP's own memory limit.
FIX 03

Check whether your host overrides it

  1. If the same message comes back and the number has not changed, the host fixes the limit and WordPress cannot raise it. I tested this with a limit set by php_admin_value in the Apache config: the message kept showing 33554432 even with WP_MEMORY_LIMIT set to 256M.
  2. In your hosting control panel, look for PHP settings, MultiPHP INI Editor, or similar, and raise memory_limit there. Hosts that use PHP-FPM often read a .user.ini file in the site root, where memory_limit = 256M is the line to add.
  3. On Apache with PHP as a module, php_value memory_limit 256M in .htaccess also works. On any other setup that line causes a 500 error, so read the 500 Internal Server Error first.
  4. If you cannot change it, ask your host to raise it, quoting the exact message. Shared plans often cap it at a fixed value, so ask what yours is.
FIX 04

Fix the admin-only case

  1. In the dashboard WordPress raises the limit to WP_MAX_MEMORY_LIMIT, which defaults to 256M unless PHP's own limit or your WP_MEMORY_LIMIT is higher. If a dashboard task still runs out, set it higher: define( 'WP_MAX_MEMORY_LIMIT', '512M' );.
  2. Image resizing, imports and exports use this admin limit too. For uploads, shrink very large images before uploading.
  3. Run heavy jobs through WP-CLI when you can. WP-CLI uses the command-line PHP, which can have a different, often higher, memory_limit. Check with php -r 'echo ini_get("memory_limit");'.
FIX 05

Find what is using the memory

  1. Raising the limit again and again hides a bug. If 256M is not enough for an ordinary page, something is wrong.
  2. Deactivate plugins one at a time, starting with the one named in the error path. With WP-CLI, wp plugin deactivate name --skip-plugins works even when the site is down.
  3. Test with a default theme: wp theme activate twentytwentyfive --skip-themes.
  4. If the error appears on one screen only, such as an import or a report page, note the exact steps and send them to the plugin author with the full message.
  5. Run wp plugin list --status=active and update what has an update. A memory bug is often already fixed.

PHP gives every request a fixed amount of memory. When a page needs more, PHP stops it and writes this message. It is a limit set per request, not a sign that the server is out of memory.

What visitors see#

With debugging off, visitors do not see this text. On WordPress 7.1.4 I triggered it with display off and got the standard critical error page with a 500 status, which is how most live sites show it. The exact Allowed memory size line then appears only in the log. With WP_DEBUG_DISPLAY set to true, or on servers where PHP displays errors, the line appears on the page.

Plain text on a white page: Fatal error: Allowed memory size of 41943040 bytes exhausted (tried to allocate 62918656 bytes) in a file under wp-content/mu-plugins, on line 2.
The message with errors displayed, on WordPress 7.1.4. PHP's limit was set to 32 MB, so WordPress raised it to 40 MB, and a test plugin asked for about 60 MB at once. The test server has html_errors off, so the text is plain; with it on, PHP bolds the words Fatal error.

How WordPress sets the limit#

WordPress works out two limits at start-up, from wp-includes/default-constants.php:

  • WP_MEMORY_LIMIT: used on every request. The default is 40 MB on a single site and 64 MB on multisite.
  • WP_MAX_MEMORY_LIMIT: used in the dashboard for heavy tasks. The default is 256 MB, unless PHP's own limit or your WP_MEMORY_LIMIT is higher.

It only ever raises PHP's limit. If PHP is already set to 128 MB, a WP_MEMORY_LIMIT of 40M does not lower it. If PHP is set to 32 MB, WordPress tries to raise it to 40 MB. That is why the message I produced reported 41943040 bytes and not 33554432. If the setting is locked by the host, WordPress takes PHP's own value and does not try to change it.

Five stacked steps. PHP starts with its own limit. WordPress raises it to WP_MEMORY_LIMIT, 40 MB on one site and 64 MB on multisite, and never lowers it. In the dashboard it uses WP_MAX_MEMORY_LIMIT, 256 MB. A request that needs more stops with the limit in force printed. The fix is to raise WP_MEMORY_LIMIT, or ask the host if the number stays the same.
Which limit is in force depends on a few settings, applied in this order. The number in the message is the one that won.
What you see in the messageWhat it tells you
41943040PHP's limit was below 40 MB, and WordPress raised it to its 40 MB default
134217728The host's limit is 128 MB, and WordPress did not change it
The same number after you set WP_MEMORY_LIMITThe host locks the limit, or wp-config.php was not the file that loaded

Choosing a value#

These figures are my own rule of thumb, not an official requirement. Check the minimums your page builder or shop plugin documents.

  • 128M is a reasonable floor for a site with a page builder or a shop.
  • 256M suits most sites that import data, run backups or process images.
  • Above 512M, look for the cause instead of raising the limit. A page that needs that much usually has a bug behind it.

After it is fixed#

Reload the failing page and the main pages, and run the task that failed once more. If you made a change to wp-config.php, keep a copy of the working file; the wp-config.php generator can rebuild the memory lines. If the task now runs out of time instead of memory, see maximum execution time exceeded. If the host raised the limit for you, ask what the new value is, so you know when you are close to it.

Sources

  1. PHP: memory_limit · What the directive limits: memory a single script may use
  2. WordPress core: default-constants.php · wp_initial_constants() sets WP_MEMORY_LIMIT and WP_MAX_MEMORY_LIMIT. Checked at 6.8.3; the defaults (40M, 64M, 256M) are the same on the 7.1.4 test site
  3. WordPress core: wp_raise_memory_limit() · Raises the limit for a context and never lowers it
  4. WordPress: editing wp-config.php · Where constants such as WP_MEMORY_LIMIT go
Newsletter

One email when something breaks or changes.

New plugins and re-tested guides, about twice a month. Never a sales pitch.