PHP from memory, calling the last random function?

Possible duplicate:
PHP Fatal error: Out of memory (80740352 allocated) (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 any way to handle this error? Maybe a function call is being made? This is not a true stack overflow; it is a limitation imposed by the system. It would seem that there will be a bit of flexibility. I cache a lot of data locally in memory for processing, but I have a garbage collection function. I already have a function to check the memory usage and free the memory if it exceeds a certain limit, but sometimes I miss. If I could call my function this "fatal" mistake ... Well, in an ideal world, a program should be able to recover.

My php.ini setting is in memory_limit = 500M.

Any thoughts?


Many thanks to everyone who suggested commenting on this, but thanks too much @Wrikken for the great suggestion.

Here is 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 set the php.ini memory limit much higher than what I would really like to run, and the tick function takes care of monitoring the memory and freeing up memory as needed.

+7
source share

All Articles