Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:66485 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 65545 invoked from network); 6 Mar 2013 09:02:51 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 6 Mar 2013 09:02:51 -0000 Authentication-Results: pb1.pair.com smtp.mail=julienpauli@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=julienpauli@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.220.170 as permitted sender) X-PHP-List-Original-Sender: julienpauli@gmail.com X-Host-Fingerprint: 209.85.220.170 mail-vc0-f170.google.com Received: from [209.85.220.170] ([209.85.220.170:59221] helo=mail-vc0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 6E/30-58818-A3607315 for ; Wed, 06 Mar 2013 04:02:51 -0500 Received: by mail-vc0-f170.google.com with SMTP id p16so4726597vcq.1 for ; Wed, 06 Mar 2013 01:02:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:mime-version:sender:in-reply-to:references:from:date :x-google-sender-auth:message-id:subject:to:cc:content-type; bh=3skW0GZMIFAUOLzEgT8gApdoNoW7gkv4Z/4MoT9PN1o=; b=u90+HwrGxM8dkUB4gEdraLHd0eWwUwF4Y/Oy+XVFQ5bHle425bYa+nAvjjf/6uscQR Xov5/QDKWY8qRDVFqYFdfk6llRdXRi2Rd1WJrnaJGQ7F6jZG5q7ENm//zLWLQyDIOGIt S4v9OBfEf0gNeI5EeIFqxIP1NHjf7R58WBAA4Qv2B3OoHwcbeyijXXCi/XFiXGIUPauR 8ROtSBiyJjVWOHfugdDWdVspdJRKpNFolYReCfIuOXqeshCWMZ523Tx2fkEdKLiNfxIc btwSPi7xB0TpEyDnE3EAgUNF9ejmgEwMPcaS5hA2F9pDW+RpYTNC1KHoOZB/m7zr0UGf 6qSA== X-Received: by 10.52.91.39 with SMTP id cb7mr9590907vdb.71.1362560568249; Wed, 06 Mar 2013 01:02:48 -0800 (PST) MIME-Version: 1.0 Sender: julienpauli@gmail.com Received: by 10.221.9.133 with HTTP; Wed, 6 Mar 2013 01:02:08 -0800 (PST) In-Reply-To: <0f6601ce19de$06ead350$14c079f0$@starin.biz> References: <0f1001ce19ce$8ce5a260$a6b0e720$@starin.biz> <0f6601ce19de$06ead350$14c079f0$@starin.biz> Date: Wed, 6 Mar 2013 10:02:08 +0100 X-Google-Sender-Auth: zS5C9Q4RugAVGQ4ETQe2Y7wQFII Message-ID: To: nathan@starin.biz Cc: internals@lists.php.net Content-Type: multipart/alternative; boundary=20cf3071c9bca80f5f04d73ddabd Subject: Re: [PHP-DEV] Memory warning hook From: jpauli@php.net (Julien Pauli) --20cf3071c9bca80f5f04d73ddabd Content-Type: text/plain; charset=ISO-8859-1 One should try ext/memtrack http://pecl.php.net/package/memtrack Also ext/memprof https://github.com/arnaud-lb/php-memory-profiler/ Julien.Pauli On Tue, Mar 5, 2013 at 9:14 PM, wrote: > >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.ticks > > 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. > > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > --20cf3071c9bca80f5f04d73ddabd--