“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.

TroubleshootingIntermediate2 min readUpdated

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 free PHP hosting trial: 30 days free with no card, then £0.99 a month.

Popular

Tip: press / to search from any pageSee all results