Skip to content

PHP memory limit

The PHP memory limit is the most memory one request to a site may use before PHP stops it. WordPress asks for 40 MB on ordinary pages and 256 MB in the dashboard unless you set otherwise, and it can only raise the limit as far as the host allows.

By
WP Ministry
Published

In short

  • The limit is a ceiling for each request, not memory handed to your site. Raising it does not make pages faster.
  • WP_MEMORY_LIMIT is what WordPress asks for on every page, and WP_MAX_MEMORY_LIMIT what it asks for in the dashboard. PHP's own memory_limit, set by the host, has the last word.
  • If a line in wp-config.php changes nothing, the host does not let the limit be raised from there. Ask the host.

The PHP memory limit is the most memory one script may use. PHP, the language WordPress is written in, runs a separate script for each request to a site, and the limit applies to each one on its own. PHP's manual says it is there to stop a poorly written script from eating all the memory on a server. A script that asks for more is stopped where it stands.

It is a ceiling, not an allowance. A page that needs 30 MB uses 30 MB whether the limit is 64 MB or 512 MB, so raising the limit does not make a site faster. It only lets a request that was being stopped run to the end.

Three settings, one limit

SettingWhere it is setWhat it isDefault
memory_limitPHP's own configuration, by the hostThe limit itself.128M in PHP. A host may set another.
WP_MEMORY_LIMITwp-config.phpWhat WordPress asks for on every request.40M, or 64M on a multisite network
WP_MAX_MEMORY_LIMITwp-config.phpWhat WordPress asks for when it has heavier work: dashboard screens opened by an administrator, image processing and scheduled tasks.256M

Two rules decide what you get:

  • WordPress only raises the limit. If PHP's own setting is already higher than WP_MEMORY_LIMIT, WordPress leaves it alone. A site on a server set to 128M runs its pages at 128M, not 40M.
  • It can raise the limit only where the host lets a script change it. Where the host does not, WordPress takes the server's value as its own and the lines in wp-config.php change nothing. From PHP 8.5 a host can also set max_memory_limit, a cap that memory_limit cannot be raised above.

Where you meet it

In an error, on screen or in the log:

text
PHP Fatal error:  Allowed memory size of 134217728 bytes exhausted (tried to allocate 1052672 bytes)

The first number is the limit in bytes. 134217728 bytes is 128 MB.

And under Tools, then Site Health, on the Info tab. Server has the row "PHP memory limit" and, when the dashboard runs with a different one, "PHP memory limit (only for admin screens)". WordPress Constants has WP_MEMORY_LIMIT and WP_MAX_MEMORY_LIMIT.

What goes wrong

Common questions

What should the WordPress memory limit be?

Enough for the heaviest page your site builds. WordPress itself asks for 40M and raises that to 256M for dashboard work. WooCommerce's server requirements ask for a WordPress memory limit of 256 MB or greater. Past that, look for the cause before you raise the number again.

I set WP_MEMORY_LIMIT and the PHP memory limit did not change. Why?

There are three usual reasons. The value you set is lower than PHP's own limit, and WordPress never lowers it. The line sits below the stop-editing line in wp-config.php, where it is read too late. Or the host does not let the limit be changed from a script, and only the host can raise it.

Not sure what is wrong?

Tell us what you see. We reply with the cause and a fixed quote, and the diagnosis is free.