Possible Duplicate:
PHP Fatal error: Out of memory (allocated 80740352) (tried to allocate 12352 bytes) in
We all know this error:
Fatal error: Out of memory (allocated 32016932) (tried to allocate 25152 bytes)
Is there a way to handle this error? Maybe a function call that is executed? This isn't a true stack overflow, it's a limit imposed by the system. One would think there would be a little bit of flexibility here. I cache a lot of data locally in memory for processing, but I have a garbage collection function. I already have the function setup to check the memory usage and free memory if it's over a certain limit, but I miss sometimes. If I could call my function on this "fatal" error... Well, in an ideal world, the program should be able to recover.
My php.ini setting is at memory_limit = 500M.
Any thoughts?
Many thanks to everyone who offered a comment on this, but extra thanks to @Wrikken, for his excellent suggestion.
Here's what I ended up doing:
declare(ticks=1);
register_tick_function('TickFunction');
function TickFunction() {
if(memory_get_usage()>220000000) // 220M
{
GlobalDataStore::CheckMemory(); // my garbage collection function
}
}
I have the php.ini memory limit set much higher than I would actually like it to run, and the tick function takes care of the memory monitoring and freeing memory on an as needed basis.