Skip to content

WordPress Memory Limit Increase: Where the Number Lives

A WordPress memory limit increase fixes one error and reveals another: the message says the allowed size is exhausted, and the number behind it is set in three places that override each other.

The order matters. PHP has a limit, WordPress has two constants on top of it, and the host can cap both. Raising the wrong one changes nothing, and the site keeps dying on the same page.

The error and what it means

“Allowed memory size exhausted” is not a plugin bug by itself. It means one request asked for more memory than the process was allowed to hold. A page builder, an import, a backup or a scanner can each cross the line on a site that is otherwise healthy.

The number in the message is the limit, not the usage. Compare it with the site health screen and with WP_MEMORY_LIMIT, and the picture becomes clear.

Three numbers that stack

PHP’s memory_limit is the ceiling for the process. Nothing above it can help, because the process is killed first.

WP_MEMORY_LIMIT raises the limit for the front end of WordPress. WP_MAX_MEMORY_LIMIT raises it for admin work: uploads, imports, image resizing. The second one matters for the tasks that usually fail.

WordPress raises its own limits only up to the PHP ceiling. Setting WP_MEMORY_LIMIT to 512M on a host with 128M gives you 128M and a false sense of work done.

Where to set it

In wp-config.php, before the line that requires wp-settings.php:

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

In PHP config, memory_limit = 256M in php.ini, or in .user.ini on hosts that read it, or in the PHP-FPM pool for a server you manage.

A php.ini change needs a restart of PHP-FPM or the web server. A constant in wp-config.php takes effect on the next request without a restart.

Which one is failing

A front-end page dies: the constant is the lever. An upload or an import dies with the same message: the max constant and the PHP ceiling are the levers. A backup plugin dies: it usually runs in admin, and it often needs more than the site does.

The site health screen shows the current PHP limit. Compare it with the constants, and check whether the host caps the value in its panel.

Raising it without hiding a problem

Doubling the limit buys time, not a fix. A plugin that loads the whole product catalogue into memory will need the doubled number again next year, and eventually the request will hit the execution time instead.

Find the request that fails. The error log names the file and the line, and a slow query log or a profiler names the query. A memory limit is a guardrail, and moving the guardrail is not the same as removing the traffic.

When the host says no

Shared hosting often locks memory_limit at 128M or 256M. .user.ini may be ignored, and ini_set from a plugin may be disabled. In that case the options are: reduce the work per request, split the import, or move to a plan where the number is real.

Moving hosts to raise memory is the last resort. Measure first: if the site runs fine except one import, the import is the problem.

Questions we hear

Does a higher limit slow the site?

No. It is a ceiling, not an allocation. Memory is used when a request needs it.

Can a plugin raise the limit?

Some try, with ini_set, and many hosts block it. The constant in wp-config.php is the reliable path.

Why does the number go back after an update?

The hosting panel or a deployment rewrites the config. Put the value in a file the panel does not manage, and check it after each update.

What about multisite?

The constants apply per site, and the PHP ceiling is shared. A network with a heavy site usually needs the higher value on all of them.

Next step

Read the PHP limit first, then set WP_MAX_MEMORY_LIMIT for the admin work, then look for the request that fails. The upload limit article covers the size limits next to this one, the PHP configuration page lists the values that matter, and the prices name the tier. WordPress documents the constants in its wp-config reference.