Skip to content

How to Fix “Allowed Memory Size Exhausted” in WordPress

Read the message Allowed Memory Size Exhausted correctly, restore the site with minimal risk of change, and find the plugin or user request in principle.

Author Bipida Editorial Team Published
Share this article

If the WordPress is a messageAllowed memory size of ... bytes exhaustedA PHP processor failed to allocate more memory. The numbers inside the message, file, and last allocation line are indexed; but the last file is not necessarily the primary factor of consumption. The immediate goal is to restore the service securely and the primary goal is to find the request, plugin, or data running.

Quick action:Save the full text of the error and time, backup it, and identify the problem with which it is being acted. If the site is unavailable, turn off the recent rollback or suspected controlled plug-in. Limited memory increases only when there is enough RAM, a temporary measure; not a final diagnosis.

What does the error message say?

PHP Fatal error: Allowed memory size of 268435456 bytes exhausted
(tried to allocate 20480 bytes) in /path/to/file.php on line 123

In this example, the processing ceiling was 256 MB and the next allocation failed. The phrase tried to allocate does not imply that the total consumption was only the same small amount; the previous processing is close to the ceiling.

If the whole site is down.

  1. Record the current error and the last change.
  2. Have a recoverable copy of the files and database.
  3. If an error occurs immediately after activating the plugin, disable the same plugin from the panel or WP-CLI.
  4. If the panel does not open, renaming the add-on folder at the emergency path file level is necessary; enter the original name and change only the specified target.
  5. Test the opcode and application caches according to the environment cleaning and site smoke test.
wp plugin deactivate plugin-slug

plugin-slugDo not disable all the plugins for no reason; checkouts, payments or important jobs may be stopped in the store.

If only one operation goes wrong.

When the homepage is healthy but the import, PDF, page builder editing or image processing fails, check the same input operation. The file size, batch record number, image dimensions, API response and query result number can be decisive. Repeat the operation with a small sample in staging.

If the error only occurs in cron, find the name of the hook and row. Repeatedly executing a failed job may create a duplicate record or more pressure. Before retry, check whether the job is safe to re-execut.

Read the active value from the context correctly.

A website is usually run with PHP-FPM or a web handler, but SSH may have another PHP CLI.php -iOnly the CLI setting shows the same command. Site Health and pool settings for the web context are more appropriate.

WordPress constants don't always override the system ceiling either.The PHP and WordPress memory run-out guide.Read it.

Temporary memory boost in WordPress

In the environment that the host allows, the following value can be edited before the stop line inwp-config.phpIt is defined as:

define( 'WP_MEMORY_LIMIT', '256M' );

The sample number is not a general version for all sites. If PHP or hosting has another ceiling, this constant may be invalid. Measure the server's current and RAM before changing and review the temporary value after detecting it. Do not duplicate multiple definitions in the file.

The setting is in PHP-FPM or

Depending on the architecture, the value may be inphp.iniThe exact file and service of each project varies; there is no general command to reload all environments. First identify the effective source of the configuration and check the syntax, then controlled reload the related service.

If multiple sites are in a pool, increasing the ceiling of a site can change the total capacity. The number of workers, average and peak consumption, RAM database and system margin should be included in the calculation.

How can we find the real culprit?

  1. Create a request or a job that can be reproduced.
  2. Check the stack trace and the first project file on the path.
  3. Record the latest version and changes to the plugins and formats.
  4. Isolate the suspect or large entrance on the staging plug.
  5. Check query and data volume and evaluate pagination/batching.
  6. Compare peak memory before and after the change.

If an error is initiated after the update, rollback of the compatible version in staging is more reliable than direct editing of the vendor code.Secure log debug.logUse it.

Common scenarios

It's a very big picture.

The memory required to decode an image can be much larger than the size of a compact file. Reducing dimensions before uploading or assigning processing to a suitable service is better than raising an unlimited ceiling.

Importing product or content

Batch the file, test the mapping and record number on the staging, and check the effect of the semi-input records before retrying.

Page builder or shortcode

Your structure in you, unlimited query or recursive rendering may increase consumption.

Backup within the same PHP request

Compressing large files in a web request can consume both memory and runtime. A streaming tool or controlled command line job may be more appropriate.

What are we not doing?

  • Putting it down.memory_limit=-1On the production.
  • Raise the ceiling until OOM Killer stops all service.
  • Edit the original file without the upgrade path
  • Re-implementation of import and payment job without idempotency checks
  • Showing fatal error and server path to visitor
  • Assuming the last message file is the source of the leak.

Confirmation of the problem.

It's not enough to just open the homepage. Run the same operation with controlled input, see the new log and control peak memory, time and data outcomes. Try out backlogs in the store, checkout and jobs. If the ceiling changes, monitor the effect below normal concurrency.

When is a professional review necessary?

If after the obvious factor is disabled, consumption continues to increase or memory increases cause the server to press full, profiling should be done outside of trial and error production.The technical troubleshooting service of WordPress.For request tracking, the plugin and the capacity of PHP-FPM correspond to the same error.

Common Questions

Is 256 megabytes always enough?

No, workloads vary. The number should be determined based on the size of the operation, the plugins and the total capacity.

Why did the wp-config change remain error-prone?

It may be that PHP or the roof host is running, the definition is in the wrong place or another CLI/FPM context error.

Does deleting the cache solve the problem?

Only if the cache data is part of the cause.

Is this the same critical error?

It can cause a critical error page, but that public message has other causes.Log critical errorIt determines the real cause.

Why Does WordPress Exhaust PHP Memory?
Identify the difference between PHP memory_limit and server RAM, find the WordPress user request, and address the cause instead of the blinding memory boost.