Fixing “Allowed memory size exhausted”

The full message reads “Allowed memory size of … bytes exhausted (tried to allocate … bytes)”. It means a single request tried to use more memory than PHP’s memory_limit allows. The quick fix is to raise that value; the real fix is to find who used it.

Finding who used it

At the end of the message there is a path and a line number. That path answers the question faster than any guess.

The path points to… It means What to do
wp-content/plugins/name A plugin is using too much, usually on a heavy task (backups, imports, reports). Raise the limit so the task can finish, then look for a newer version or a lighter alternative.
wp-content/themes/name The theme or a page builder loading a lot. Raise the limit. If it keeps running short, the theme is heavy for the plan.
Image files (gd, imagick) A huge photograph being processed. Shrink the image before you upload it. The cost grows with the dimensions, not the file weight.
Your own code, always in the same place A loop that never ends, or a whole list loaded at once. Here, raising the limit only delays the error. Fix the code.

Raising the limit

1 In cPanel open Select PHP Version, pick the version the site uses and open the Options tab.
2 Find memory_limit and choose a value above the current one, one step at a time.
3 If only one application needs it, put a .user.ini in its folder instead, with a line such as memory_limit = 256M (an example). See where to set each value.
4 WordPress also has a limit of its own, changed in wp-config.php. See giving WordPress more memory.
5 Repeat the action that caused the error. If it goes through, stop here.

To confirm the new value is in force, open a file containing <?php phpinfo(); in the site folder and look for memory_limit: the Local Value column is the one that counts. If the number did not move, it was saved in the wrong place, or the site runs on another PHP version. And before you raise the limit by much, try deactivating plugins one by one and repeating the action: if the error disappears with one of them off, the limit was never the problem.

memory_limit is not your account’s memory. It is the ceiling per request. The account has its own memory and process limits, and when a request hits those the result is a 500 or 508 error, not a higher limit. See the limits nobody advertises and website errors explained.
If the message only appears on a heavy task (importing, exporting, building backups), consider running that task from the command line or from cron, where there is no web request. See running a PHP script from a cron job.

Raised the limit and the message is back? Send us the whole message, with the path and the line.

Open a support ticket

SEE ALSO

PHP limits: memory, time, upload size and the one that fails silently

php.ini and .user.ini: where to set a value

Giving WordPress more memory

The limits nobody advertises

RECOMMENDED PRODUCT

Web hosting with cPanel

Domain and SSL included, daily backups and the panel you already know. from 5.940,00 Kz/mo (3-year plan, with coupon)

See plans
  • 0 Users Found This Useful
Was this answer helpful?