Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to recover from a fatal error "Allowed memory size exhausted"

Do you know any solution to recover from the PHP fatal error : "Allowed memory size ... exhausted"

I have a shutdown function that is called when a fatal error appear. This function create an ErrorException from it, and logs it.

The problem is : when there is no more memory available, it can't log the error (I log in Firebug, via FirePHP, with Zend Framework).

So what i mean by "how to recover from it", is how to perform basic error log, and let Zend Framework send the Headers, so that the error is logged (in Firebug in my case) as any other error ?

Thanks

like image 698
Matthieu Napoli Avatar asked Feb 23 '10 14:02

Matthieu Napoli


People also ask

How do I fix fatal error allowed memory size?

To fix the error, you have to manually increase the default PHP memory limit set for your server.

What is the maximum PHP memory limit?

Increasing the PHP memory limit The default memory limit is 256M and this is usually more than sufficient for most needs. If you need to raise this limit, you must create a phprc file.


1 Answers

This worked fine for me:

try {
    ini_set('memory_limit', (ini_get('memory_limit')+1).'M');
} catch(Exception $e) {}

This assumes your memory limit is in the format 123M.

like image 63
Tgr Avatar answered Sep 21 '22 03:09

Tgr