Fixing the Allowed Memory Size Exhausted Error in WordPress

Raising the PHP memory limit fixes this error for a while. How to raise it correctly, and how to find what is actually eating the memory.
Allowed memory size exhausted: turned-on MacBook Pro wit programming codes display

A message like “Fatal error: Allowed memory size of 134217728 bytes exhausted” means a PHP process on your site used more memory than the server allows, so it stopped. The allowed memory size exhausted error is one of the most common WordPress fatal errors, and it’s also one of the most misunderstood. You’ll learn how to read the message, how to raise the limit in the right place, and how to tell when more memory is only hiding a deeper problem that will come back.

What “allowed memory size exhausted” tells you

Every time someone loads a page, PHP gets a fixed amount of memory to build it. If the work needs more, PHP stops with a fatal error. Depending on your setup, visitors see a white screen, a 500 error or the “critical error” message.

The number in the message is the limit, in bytes. Here’s how to translate the common ones:

  • 67108864 bytes is 64 MB.
  • 134217728 bytes is 128 MB.
  • 268435456 bytes is 256 MB.
  • 536870912 bytes is 512 MB.

The message also names a file. Be careful here. That file is where memory ran out, not necessarily what used it all up. It’s like the last person to step into a full elevator. Often it is a core WordPress file, while the real cause is a plugin that loaded far too much data earlier in the request.

Raise the limit the right way

WordPress has two settings of its own that sit on top of the server’s PHP limit:

  • WP_MEMORY_LIMIT controls the front end. WordPress defaults to a low value for single sites.
  • WP_MAX_MEMORY_LIMIT controls admin tasks such as image processing and updates, and defaults higher.

To raise them, open wp-config.php and add these lines above the comment that says to stop editing:

  • define('WP_MEMORY_LIMIT', '256M');
  • define('WP_MAX_MEMORY_LIMIT', '512M');

Then confirm it worked. Go to Tools, then Site Health, then the Info tab. Under “Server” you’ll see the PHP memory limit, and under “WordPress Constants” you’ll see the WordPress values. If the values have not moved and the error continues, your host is probably capping memory, and WordPress can’t go above that cap.

If wp-config.php was not enough

The server limit is set by your host. Depending on the host you can change it in one of these places:

  1. A PHP settings screen in the hosting panel. In cPanel this is often called the MultiPHP INI Editor.
  2. A .user.ini or php.ini file in your site’s root with the line memory_limit = 256M.
  3. A support ticket. Some managed hosts set the limit per plan and will raise it on request.

Make one change at a time and check Site Health after each. If you edit three files at once, you will not know which one worked, and the next developer will find conflicting values in three places.

For most business sites, 256 MB is plenty. A busy WooCommerce admin or a large page builder site may need 512 MB. If you find yourself pushing past that, stop raising and start investigating.

When more memory is not the answer

If the error comes back at 512 MB, something is wasting memory. Raising the ceiling again only buys time. These are the causes I find most often:

  • A plugin that loads every product, order or user into memory at once instead of in batches.
  • A huge autoloaded options table, where plugins store large chunks of data that WordPress loads on every single page.
  • Very large image uploads. A phone photo straight from the camera can need a lot of memory to resize.
  • Import, export and backup plugins doing big jobs inside a web request.
  • A loop in custom code that never ends.

How to find the culprit

  1. Install Query Monitor on a staging copy. It shows peak memory use for each page, so you can see which screens are heavy.
  2. Deactivate plugins one at a time on staging and watch the number drop. The plugin that causes the big drop is your suspect.
  3. Check the size of autoloaded data in wp_options. Leftovers from deleted plugins are common and safe to clean, once you have a backup.
  4. Read debug.log for the full error line and the time it happens. Errors at the same minute every hour usually point to a scheduled task.

Write down what you find. A short note such as “the product import tool peaks near 400 MB” is worth a lot the next time someone sees the error, and it tells you whether replacing that plugin is worth the effort.

Where the error shows up, and what that tells you

When uploading images

Resize photos to a sensible width before upload. A hero image rarely needs to be wider than about 2,000 pixels. Smaller uploads also make the site faster.

In the page builder editor

Editors like Elementor load a lot at once. Raise WP_MAX_MEMORY_LIMIT and remove add-on packs you don’t use. Very long pages with hundreds of widgets are worth splitting.

During imports, exports and backups

Run large jobs in smaller batches, or let a developer run them from the command line with WP-CLI, which doesn’t hit the same web request limits.

In WooCommerce admin

Order screens and reports on stores with years of history can be heavy. Clean up old sessions and transients, and check which extensions add columns or data to every order row.

If memory errors keep returning, the site usually needs a broader cleanup. My speed optimization work covers exactly this: leaner plugins, smaller options tables and proper caching.

Checklist

  • Translate the byte number into MB to see the current limit.
  • Add WP_MEMORY_LIMIT and WP_MAX_MEMORY_LIMIT to wp-config.php.
  • Confirm the real values in Site Health.
  • Raise the server limit in the hosting panel if needed.
  • Stop at 512 MB and look for the cause instead.
  • Use Query Monitor and plugin testing on staging to find the heavy plugin.
  • Resize images before upload and run big jobs in batches.

You might also find these useful: WordPress not sending emails and how to fix the WordPress critical error safely.

FAQ

Is it safe to raise the PHP memory limit?

Yes, within reason. 256 MB or 512 MB is normal. Setting it to unlimited is a bad idea, because one runaway process can then slow the whole server.

Why did my change in wp-config.php do nothing?

WordPress can only raise the limit as far as your host allows. Check Site Health. If the server is capping it lower, change it in the hosting panel or ask your host.

Will more memory make my site faster?

No. Memory is a ceiling, not a speed setting. It stops crashes but doesn’t make pages load faster.

Do I need better hosting?

Sometimes. If your host caps memory low and will not raise it, a better plan helps. But fix wasteful plugins first, or you’ll carry the problem to the new host.

Tired of the same memory error every few weeks? I can find what’s using the memory and fix it at the source. Get a free website review, or see my WordPress error fix service.

Share this article

Shehzad Akram

About the author

Shehzad Akram

Senior WordPress and Shopify developer in Lahore, Pakistan, Top Rated on Upwork with 100% Job Success. I write these notes from real client work: what broke, what fixed it, and what I check every time.

Keep reading

More notes from real client work