Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:66478 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 90010 invoked from network); 5 Mar 2013 20:14:27 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 5 Mar 2013 20:14:27 -0000 Authentication-Results: pb1.pair.com smtp.mail=nathan.bruer@starin.biz; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=nathan.bruer@starin.biz; sender-id=unknown Received-SPF: error (pb1.pair.com: domain starin.biz from 207.198.105.69 cause and error) X-PHP-List-Original-Sender: nathan.bruer@starin.biz X-Host-Fingerprint: 207.198.105.69 hawk.starindns.com Received: from [207.198.105.69] ([207.198.105.69:38691] helo=hawk.starindns.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 88/35-58003-12256315 for ; Tue, 05 Mar 2013 15:14:27 -0500 Received: from 173-167-160-145-illinois.hfc.comcastbusiness.net ([173.167.160.145]:64127 helo=NathanBruerHP) by hawk.starindns.com with esmtpa (Exim 4.80) (envelope-from ) id 1UCyFh-0002e1-41 for internals@lists.php.net; Tue, 05 Mar 2013 14:14:21 -0600 Sender: "Nathan Bruer" To: References: <0f1001ce19ce$8ce5a260$a6b0e720$@starin.biz> In-Reply-To: Date: Tue, 5 Mar 2013 14:14:22 -0600 Message-ID: <0f6601ce19de$06ead350$14c079f0$@starin.biz> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Mailer: Microsoft Outlook 14.0 Thread-Index: AQJcCX4fXpv3hZU//TS/XYhFnJOwugI1EOcVAoJRY9OXVenAgA== Content-Language: en-us X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - hawk.starindns.com X-AntiAbuse: Original Domain - lists.php.net X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - starin.biz X-Get-Message-Sender-Via: hawk.starindns.com: authenticated_id: nathan.bruer@starin.biz Subject: RE: [PHP-DEV] Memory warning hook From: nathan@starin.biz >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. I agree this probably is a good solution and I personally do use it = along with shared memory tools, however there may be cases where the dev = may gain more benefit from having a memory-warning installable trigger = in place. This would allow things like allowing the dev to release = certain cache objects before others or something completely different = that I have not thought of yet. > 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. Yes running the GC is much faster except they are two completely = different processes... in my example the dev is keeping references to = data for possible future use later on however it's not possible to know = when to release these references so php's GC can collect them if the = user does not implement something quite juristic like ticks or frequent = function calls throughout a code base. >You can use ticks :) > >http://php.net/control-structures.declare#control-structures.declare.tic= ks Yes Ticks are something useable (like said above) however I have found = ticks are clunky, frequently shunned, and you'd be ticking for no reason = most of the time.