“Allowed memory size exhausted” PHP error

What the PHP memory exhausted error means, how to check the memory limit, and how to reduce memory use rather than only raising the limit.

Guide2 min readLast updated
On this page
  1. Does this match what you’re seeing?
  2. 1. Find which script and when
  3. 2. Check the current limit
  4. 3. Fix the cause where possible
  5. 4. Raise the limit if it’s genuinely needed
  6. Common questions

Does this match what you’re seeing?

  • Log shows ‘Allowed memory size of N bytes exhausted’
  • Large imports, exports or image uploads fail
  • The page is blank or shows a 500 error
PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 65536 bytes)

A single request tried to use more memory than memory_limit allows (134217728 bytes = 128MB). The “tried to allocate” figure is just the last small piece that tipped it over.

1. Find which script and when

The error log line includes the file and line. Note what triggered it: a particular page, an import, an image upload, a cron job.

2. Check the current limit

Look at memory_limit in phpinfo. How to check which PHP version your site is using

3. Fix the cause where possible

TriggerBetter approach
Importing a large CSV or databaseProcess in batches; import databases outside PHP (Importing a database that’s too large for phpMyAdmin)
Image processingResize images before uploading
Loading a whole table into an arrayPaginate queries or iterate with a cursor
A plugin on every pageReplace or reconfigure that plugin
Backup plugins zipping the whole siteUse DirectAdmin’s backup feature instead

4. Raise the limit if it’s genuinely needed

See whether memory_limit is adjustable for your account. Changing PHP settings: memory_limit, upload size and execution time For WordPress, also set WP_MEMORY_LIMIT. “Allowed memory size exhausted” in WordPress

A page that routinely needs several hundred megabytes on a small site is a sign of a problem, not a need for a bigger limit.

Not with Traxio yet? You can try this on a real server with our PHP hosting: £0.99 a month.

Common questions

How do I increase the PHP memory limit?

Raise it in your PHP settings for the domain, or with a memory_limit line in a .user.ini file. Some directives are adjustable on shared hosting and some are fixed, so check the value with phpinfo() after changing it to confirm it applied.

Spotted something out of date or unclear? Tell us and we’ll fix it.

Keep going