Re: Memory warning hook

From: Date: Tue, 05 Mar 2013 19:00:48 +0000
Subject: Re: Memory warning hook
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-66475@lists.php.net to get a copy of this message
On Tue, 2013-03-05 at 12:23 -0600, nathan@starin.biz wrote: > As PHP applications are turning into large frameworks one of the issues > arriving is memory management. One of the issues is that many frameworks use > sophisticated caching techniques to make accessing the same data quickly, > this improves speed it is at the cost of memory. Often the developer knows > these areas that cache and often times already have functions in place to > clear out the cache, however in the case where PHP is approaching or exceeds > memory limits PHP runs the GC then dies if it cannot allocate enough memory. > If we implemented "memory warning" triggers or user function that will be > called before the GC is executed which allows the user to try and free up > some memory on their own. This hopefully would give more flexibility to > allowing these advanced caching techniques but at the same time allow the > cache to be cleared out in case memory is getting low. Running the GC is most likely faster than most cleanup routines a user could run, also usually there is not that much stuff cached in PHP scripts. If a PHP script has "tons" of data, which it can easily throw away, in memory this sounds like a smell of an bad architecture. Cache cache-worthy stuff in memcache or such and fetch only the data you need. Also: What should happen if the system runs out of memory while doing the cleanup? Anything sane doesn't sound good either. johannes

« previous php.internals (#66475) next »