More fixes

WordPress says "Allowed memory size of ... bytes exhausted"

The full message reads something like "Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 20480 bytes) in /home/.../wp-content/plugins/... on line 412". PHP, the language WordPress runs in, gives each page load a memory allowance, and this page load ran out of it. Visitors usually do not see that line: since WordPress 5.2 they see "There has been a critical error on this website", and the real message goes to the error log and to the admin email address. The message holds three clues: the allowance, the size of the last request, and the file that asked. Below is a rebuilt example (not a real client), then how to read those clues and what to change.

What a visitor sees on the home page

harborviewdental.example

What the checks found


  

Read the message first (two minutes)

  1. Find the full line. Look for an email to the site's admin address titled "Your Site is Experiencing a Technical Issue": it quotes the error and includes a recovery-mode link that lets you log in with the broken plugin paused. No email? The host's control panel has an error log (cPanel: Metrics, Errors), or the file error_log sits in the site's folder.
  2. The first number is the allowance, in bytes. 67108864 is 64 MB, 134217728 is 128 MB, 268435456 is 256 MB, 41943040 is 40 MB (WordPress's own default when the host sets nothing higher).
  3. The "tried to allocate" number says what kind of problem it is. A small number (a few thousand bytes) means the page slowly used up everything: the allowance is too small for what the page does. A huge number (tens or hundreds of millions of bytes) means one thing asked for a giant block at once, usually a bug, an endless loop or an enormous file, and raising the limit will not help.
  4. The file path names the suspect. wp-content/plugins/name/ is that plugin, wp-content/themes/name/ is the theme. A path in wp-includes is WordPress itself doing the work some plugin or a large image asked for, so look at what was happening rather than blaming WordPress.
  5. See what the site has now. Tools, Site Health, Info, then the Server section ("PHP memory limit") and WordPress Constants (WP_MEMORY_LIMIT). If you cannot log in, use the recovery link from the email.

The fixes, in the order to try them

  1. Back up first. In the host's control panel, take a backup, or at least download wp-config.php and any .user.ini or php.ini in the site folder before editing them.
  2. If the allowance is small (64 MB or 40 MB) and the request was small, raise it. 256 MB covers most small-business sites, page builders and shops included.
    • In the host's panel first: cPanel's MultiPHP INI Editor or "Select PHP Version", Options, set memory_limit to 256M. Other hosts have a "PHP settings" page with the same field. This is the setting everything else depends on.
    • Then tell WordPress: in wp-config.php, above the line that says /* That's all, stop editing! */, add define( 'WP_MEMORY_LIMIT', '256M' );
    • No panel setting? A file named .user.ini in the site's main folder with the line memory_limit = 256M works on most hosts; it can take a few minutes to apply. Only put a php_value line in .htaccess if the host's help pages say so, because on many servers that line itself takes the whole site down with a 500 error.
    • Reload Site Health: "PHP memory limit" should now read 256M. If it did not move, the host caps it for your plan, and their support is the only way to raise it.
  3. If the request was huge, or 256 MB still runs out, fix the cause instead. Update the plugin or theme the path names; if it is up to date, switch it off (Plugins, or rename its folder in wp-content/plugins in the file manager, which keeps its settings) and check the site. Then look for the plugin's known issue or a replacement. The plugin conflict guide has the one-at-a-time method when the path is not clear.
  4. If it happens while uploading photos, the photo is the load: WordPress makes several resized copies of each upload, and a 6000-pixel phone or camera photo needs a lot of memory for that. Resize photos to about 2000 pixels wide before uploading; the slow photos guide shows how, and it makes the pages faster too.
  5. If it happens only in the dashboard or the page builder, WordPress uses a second, higher allowance there (WP_MAX_MEMORY_LIMIT, 256 MB by default). It can only reach that if the host lets it, so the host's memory_limit from step 2 is still the one to check.
  6. Test: the home page and the page that failed, logged out and on your phone; the dashboard; one photo upload; and Site Health again. Then check the error log the next day for new "exhausted" lines.

What the message says, what it means, what it needs

What you findWhat it meansUsual fix
Allowance 64 MB or 40 MB, small "tried to allocate"The allowance is too small for the sitememory_limit 256M in the host panel, WP_MEMORY_LIMIT 256M in wp-config.php
"tried to allocate" in the tens or hundreds of millionsOne plugin, theme or file asked for a giant block: a bug or a loopUpdate or switch off what the path names; raising the limit will not stop it
Still runs out at 256 MB or 512 MBSomething keeps using memory until any limit is goneSame as above: find the plugin, do not keep raising the number
Only when uploading photosVery large photos being resizedResize to about 2000 pixels before uploading
Site Health still shows the old limit after the changeThe host's setting wins, or the plan caps itChange it in the host panel, or ask support
Started right after a plugin or theme updateThe new version uses more memory or has a bugRoll back or switch it off, tell its author

What not to do

Most sites need step 2 and are back in ten minutes; the rest need the plugin the message names updated or replaced. If the site is still showing the error, or the host will not raise the limit, that is what the box below is for. Related: "there has been a critical error" is how this error looks from the front of the site, and the white screen guide covers the same failure when nothing at all is shown.