Fixing "Allowed memory size exhausted" in WordPress
What the "Allowed memory size of ... bytes exhausted" error means, how to read the numbers, how WordPress sets its memory limits, how to raise them safely and how to find what's using up the memory.
If you've seen a line like this on screen, in your debug log or in a WordPress recovery mode email, your site has run out of PHP memory:
PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 20480 bytes) in /home/user/public_html/wp-includes/class-wpdb.php on line 2350
PHP gives each page load a memory allowance, and stops the page dead if something asks for more.1 Visitors usually see "There has been a critical error on this website" or a blank page. In the dashboard it can look like an upload that fails, an import that stops halfway or an editor that won't save.
The usual causes are a heavy plugin, a limit that's simply too low for what the site now does or a big job such as an import, export or backup. Raising the limit is the quick fix. Finding what's eating the memory is the real one.
Read the numbers in the error
"Allowed memory size of 134217728 bytes" is the limit that was in force. Divide by 1,048,576 (1,024 × 1,024) to get megabytes:
| In the error | Limit |
|---|---|
| 67108864 bytes | 64M |
| 134217728 bytes | 128M |
| 268435456 bytes | 256M |
| 536870912 bytes | 512M |
128M is PHP's own default,1 which is why 134217728 turns up so often. If you've already raised the limit to 256M and the error still says 134217728, your change isn't being applied. The sections below explain why.
"Tried to allocate 20480 bytes" is the last request that tipped it over, not the total. A small number like this (20 KB) means memory filled up gradually. A huge one, hundreds of megabytes, means a single job tried to grab a lot at once, often a big file or export, and a higher limit rarely fixes that. On recently updated servers, a grab that big is more likely to be stopped outright with no error at all (see the logs section below).
The file path shows where PHP happened to be when the allowance ran out, which isn't necessarily the culprit. If a plugin uses 120MB and WordPress then needs a few more kilobytes to run a database query, the error points at WordPress's database file. Treat it as a clue. Our guide to reading an error line has more on file paths.
Recovery mode works the same way. WordPress picks which plugin or theme to blame purely from that file path,2 so with memory errors the recovery email can blame an innocent plugin. If the error happened in WordPress's own files, no recovery email is sent at all.
Understand how WordPress sets its memory limit
WordPress has two settings of its own, both set in wp-config.php.3
WP_MEMORY_LIMIT is what WordPress asks for on normal page loads. The default is 40M on a normal site and 64M on multisite.4 WordPress only uses it to raise PHP's limit, never to lower it, so if your host gives PHP 128M, the 40M default does nothing and your site gets 128M.5
WP_MAX_MEMORY_LIMIT is a bigger allowance for heavier work. It defaults to 256M, or to PHP's own limit or your WP_MEMORY_LIMIT if either is higher.4 WordPress switches to it when an administrator loads an admin screen,6 when it resizes or edits images (whoever uploaded them),7 when it unzips updates8 and when it runs scheduled tasks through WP-Cron.9
Other requests, such as the block editor saving a post or a page builder saving in the background, only get the normal limit (PHP's own limit or WP_MEMORY_LIMIT, whichever is higher). That's one reason a site can browse the admin happily but fail when you click Save.
Both settings work by asking PHP to change its limit as the page loads.410 Some hosts lock that setting, and WordPress then just uses whatever PHP already has.4 From PHP 8.5, hosts can also set a ceiling nothing can go above.11 Nothing in wp-config.php gets past the host's limits.
Check your current limits in Site Health
Go to Tools→ Site Health and click the Info tab.12
- In the Server section, PHP memory limit is the limit ordinary page loads get, after WordPress has applied
WP_MEMORY_LIMIT. If WordPress raises it further for admin screens, you'll also see PHP memory limit (only for admin screens).13 - In the WordPress Constants section, look for WP_MEMORY_LIMIT and WP_MAX_MEMORY_LIMIT.13
WP_MEMORY_LIMIT showing 40M next to a PHP limit of 128M is the standard setup, and your site gets 128M. If both constants show exactly the same figure as the PHP limit and you haven't set them yourself, that's how WordPress behaves when the host has locked PHP's memory setting,4 so the host is the one to ask.
If you can't reach the dashboard, your hosting control panel usually shows the PHP memory limit in its PHP settings.
Raise the limit in wp-config.php
If the limit is 128M or lower, raising it is a reasonable first step and often gets the site working while you look for the cause.
Connect with SFTP or your hosting file manager and download a copy of wp-config.php first. It's in your site's main folder, next to wp-admin and wp-content, or occasionally the folder above.
Search the file for WP_MEMORY_LIMIT. Some hosts and plugins add it already, and PHP only uses the first definition,14 so edit the existing line rather than adding a second. If there isn't one, add this just above the line that starts /* That's all, stop editing! (it ends "Happy publishing" or, on older sites, "Happy blogging"):
define( 'WP_MEMORY_LIMIT', '256M' );
It has to go above that line, because anything below it is read after WordPress has already set its limits.3 Type it exactly as shown, quote marks and capital M included. Save, upload and repeat whatever caused the error. If the site goes blank or shows a new error straight away, put your saved copy back and check for typos.
If the error only happens during admin jobs such as imports or big uploads, you can raise the admin allowance too:
define( 'WP_MAX_MEMORY_LIMIT', '512M' );
256M is plenty for most sites, including most WooCommerce shops, and 512M suits a large shop or heavy page builder site. Going much higher, or using -1 for no limit, just lets a runaway process hog more of the server before it's stopped, which is exactly what the limit is there to prevent.1
And remember that raising the limit treats the symptom. WordPress's own documentation warns it can hide the root of the problem until it comes back later.3
Ask your host to raise the PHP limit
If Site Health shows your new WP_MEMORY_LIMIT but PHP memory limit hasn't moved and the error still quotes the old figure, your host is capping it. How PHP's limit is changed depends on the server, so check your host's help pages or ask support before trying any of these:
- Your hosting control panel. Most have a PHP settings page with a
memory_limitoption. This is the safest route when it's there. - php.ini or .user.ini. Some hosts let you add
memory_limit = 256Mto a file in your site's main folder..user.inionly works on certain server setups, and PHP rereads it every five minutes by default, so changes aren't instant.15 Keep a copy of any existing file before editing it. - .htaccess. A
php_value memory_limit 256Mline only works where PHP runs as an Apache module,16 or on LiteSpeed servers.17 On other setups the line can cause a 500 error. Only use it if your host says so, with a copy of.htaccesssaved first.
A short message is usually quickest: "I'm getting 'Allowed memory size of 134217728 bytes exhausted' on my WordPress site. Can you raise PHP's memory_limit to 256M, or tell me the most my plan allows?"
Find what is using the memory
Once the site is working, find out what pushed it over. That's what stops the error coming back.
Start with the logs
Turn on the debug log, repeat the problem and search wp-content/debug.log for "Allowed memory size". Note the time, the path and what you were doing, and look at the lines just before it for warnings from a particular plugin. Switch debugging off and delete debug.log when you've finished. On WooCommerce sites, also check WooCommerce→ Status→ Logs for the "fatal-errors" source, which WooCommerce records even with debugging off.18
If the logs stay empty, PHP may have stopped the request outright. PHP security updates released from October 2026 add a hard ceiling (by default, twice the normal limit on most sites). A request that goes past it is ended instantly with no WordPress or WooCommerce error, and the only message, "Hard memory limit of ... bytes exhausted", goes to the server's own error output rather than the PHP error log, so ask your host to check for it.19 Visitors then tend to see a 502 or 503 error instead.
Test plugins one at a time
If the log points at a plugin, start there. Otherwise deactivate plugins one at a time under Plugins→ Installed Plugins, repeating the action that failed after each.
This switches features off for visitors too, so pick a quiet time or use a staging copy. The Health Check & Troubleshooting plugin's troubleshooting mode disables plugins and switches to a default theme for your session only, while visitors see the normal site.20 It hasn't been updated for a while, so check it works on your site first. Take a backup first all the same, note which plugins were active and switch them back on afterwards. If you're locked out, our critical error guide explains how to deactivate plugins over SFTP.
Measure it with Query Monitor
The free Query Monitor plugin shows each page's memory use in the admin toolbar, and its Overview panel shows Peak Memory Usage as a percentage of your limit.21 A page sitting at 90% is the one that tips over next. Compare a light screen such as Settings→ General with the one that fails, then try again with suspect plugins switched off. Deactivate Query Monitor when you've finished, since it adds overhead of its own.
The usual suspects
- Page builders. Long pages with lots of sections can use a lot of memory to render and save, especially inside the builder.
- Import, export and backup plugins. Some load a whole file, product list or backup archive into memory at once. Smaller batches, or a lower-memory option in the plugin's settings if it has one, often work where a bigger limit doesn't.
- Large image uploads. WordPress opens the full image to make smaller copies, and scales down anything over 2,560 pixels wide or tall.22 Memory use depends on the pixel dimensions, not the file size. Our guide to media upload errors covers this.
- Big WooCommerce reports and exports. Analytics over long date ranges, huge CSV exports and bulk edits are common triggers. If background jobs are failing too, see failed scheduled actions.
- Bloated autoloaded options. Some settings load on every page, and plugins that stuff lots of data in there make every page heavier. Site Health warns "Autoloaded options could affect performance" past about 800 KB.23 Our slow admin dashboard guide explains the clean-up.
- A loop after an update. If the error started straight after an update and keeps happening however high you set the limit, the code is probably going round in circles. No limit will be enough. Roll the update back and report it to the developer.
Check if your hosting plan is the limit
Sometimes nothing is broken and the site has just outgrown its hosting. Shared plans usually cap PHP memory, and many also cap the total memory your account can use at once.
It's probably the plan if your host won't go above 128M or 256M, or the errors come at busy times rather than on one particular page, or your control panel's resource graphs show memory spikes that line up with them. Ask your host what your plan allows and what the next step up would give you. If the site is sluggish generally, see our guide to a suddenly slow WordPress site.
Common questions
Is 256M of memory enough for WordPress?
For most sites, yes. Many brochure sites never get near 128M, and 256M gives most WooCommerce shops and page builder sites a comfortable margin. If ordinary pages need more than 256M, that usually points to a plugin problem rather than a reason to keep raising the limit. Large imports and exports are the main exception, and WP_MAX_MEMORY_LIMIT exists for those.
Will raising the memory limit slow my site down?
No, not on its own. The limit is a ceiling rather than memory set aside, so a page that needs 60MB still uses 60MB.1 The risk is on small hosting plans, where a very high limit lets several heavy requests use more of the server at once, which can cause 502 or 503 errors under load. Stick to 256M or 512M.
Why does the memory error only happen in the admin?
Usually because admin work is heavier. Imports, exports, image uploads, updates and page builder editors all use far more memory than serving a cached page to a visitor. WordPress gives administrators a higher allowance on admin screens,6 but saving in the editor and many background requests don't get it, so raising WP_MEMORY_LIMIT is often what fixes those.
Why did the memory error come back after an update?
Most likely the update made a plugin, theme or WordPress itself use a little more memory, and your site was already close to its limit. Check the debug log to see what was running. If the error appeared suddenly and higher limits make no difference, the update may contain a bug, so roll it back and tell the developer.
Still running out of memory?
If you've raised the limit and still can't find what's using it all, my emergency WordPress support can track it down and fix it, and my maintenance plans catch creeping errors before they take the site down.
Description of core php.ini directives (memory_limit), PHP Manual. ↩ ↩ ↩ ↩
class-wp-recovery-mode.php (get_extension_for_error), WordPress source code on GitHub. ↩
wp-config.php, WordPress Advanced Administration Handbook. ↩ ↩ ↩
default-constants.php (wp_initial_constants), WordPress source code on GitHub. ↩ ↩ ↩ ↩ ↩
PHP Optimization, WordPress Advanced Administration Handbook. ↩
class-wp-image-editor-imagick.php and class-wp-image-editor-gd.php, WordPress source code on GitHub. ↩
file.php (unzip_file), WordPress source code on GitHub. ↩
wp-cron.php, WordPress source code on GitHub. ↩
functions.php (wp_raise_memory_limit), WordPress source code on GitHub. ↩
Description of core php.ini directives (max_memory_limit), PHP Manual. ↩
site-health.php, WordPress source code on GitHub. ↩
class-wp-debug-data.php, WordPress source code on GitHub. ↩ ↩
.user.ini files, PHP Manual. ↩
How to change configuration settings, PHP Manual. ↩
cPanel tuning: Disable PHP Override, LiteSpeed Documentation. ↩
class-woocommerce.php (log_errors), WooCommerce source code on GitHub. ↩
Description of core php.ini directives (memory_hard_limit_percent), PHP Manual. ↩
Health Check & Troubleshooting, WordPress.org Plugin Directory. ↩
Query Monitor (overview panel), Query Monitor source code on GitHub. ↩
image.php (wp_create_image_subsizes), WordPress source code on GitHub. ↩
class-wp-site-health.php (get_test_autoloaded_options), WordPress source code on GitHub. ↩