2013/3/5 Tom Boutell <t...@punkave.com>

> Can't you do this already? memory_limit can be fetched via ini_read,
> and together with memory_get_usage you should be able to check for
> this sort of thing. Admittedly having to parse memory_limit (which can
> be in various units) is not perfect.
>

This is not the same at all. When are you going to run this code? Memory
allocations happen all the time. What Nathan asked for is an event that is
triggered when the memory consumption reaches a threshold.

However, there is a different solution, which is better IMHO in the case of
caches: weak references. A weak reference automatically frees the memory of
the object, when the memory is needed.
http://php.net/manual/en/book.weakref.php.

Having said that, none of these solutions scale up to multiple servers.
This is why shared cache systems like memcached are recommended.




> On Tue, Mar 5, 2013 at 1:23 PM,  <nat...@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.
> >
> >
> >
> > Thoughts?
> >
> >
> >
> > Thanks,
> >
> > Software Developer
> >
> > Nathan Bruer
> >
> >
> >
>
>
>
> --
> Tom Boutell
> P'unk Avenue
> 215 755 1330
> punkave.com
> window.punkave.com
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
Lazare INEPOLOGLOU
Ingénieur Logiciel

Reply via email to