Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:84635 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 64069 invoked from network); 12 Mar 2015 12:35:57 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 12 Mar 2015 12:35:57 -0000 Authentication-Results: pb1.pair.com header.from=danack@basereality.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=danack@basereality.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain basereality.com from 209.85.213.44 cause and error) X-PHP-List-Original-Sender: danack@basereality.com X-Host-Fingerprint: 209.85.213.44 mail-yh0-f44.google.com Received: from [209.85.213.44] ([209.85.213.44:43904] helo=mail-yh0-f44.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 9D/C3-42021-C2881055 for ; Thu, 12 Mar 2015 07:35:57 -0500 Received: by yhaf10 with SMTP id f10so8008634yha.10 for ; Thu, 12 Mar 2015 05:35:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=MQgA0gmRglnszOcLzp2U2IGWVAvJbFnwrm7B/GL91Ig=; b=bEg0ZSdKkDnhqEKvJSTUV2ZUgcXJZPB0G18GKvY4WQkgON+A9D2Xj76MoH/AKP5tEE TlquvI2mI/AcglL0/19+TwGP1DHMZ3hZj5h454/M8cBBNc+9IpuyA79e8b84zQhQuy8V UvaI5MPdcg+9BZfsBAhIUnhcu7EJkjx8jk4oASrxKpjIK6VLmeKbeUxBViIUqiBmm8PW 1NRSvWMrZ8XlP3cx6fI1YKbIEmGTgbZEMO0gTg+XUBfTiDLk390OJT0T6Rtax2JtT4QK pD96fop0dnt3zyMrvg7EV+LEh0b5mm1UcB7q6FEPb9x5Zp5poZqZH7TmCOgVMbeM0z8b eG8A== X-Gm-Message-State: ALoCoQlfjyrVB6U2ZRXZMRkC1KPoiN0V8qFpLk++nk7AdiVE6TMwnqdBmifKkWUP808d72DbqAww MIME-Version: 1.0 X-Received: by 10.236.38.162 with SMTP id a22mr40494440yhb.167.1426163754602; Thu, 12 Mar 2015 05:35:54 -0700 (PDT) Received: by 10.170.71.86 with HTTP; Thu, 12 Mar 2015 05:35:54 -0700 (PDT) X-Originating-IP: [78.147.4.32] In-Reply-To: References: Date: Thu, 12 Mar 2015 12:35:54 +0000 Message-ID: To: Dmitry Stogov Cc: Rasmus Lerdorf , Nikita Popov , Xinchen Hui , Anatol Belski , PHP Internals Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] Safe execution timeout handling From: danack@basereality.com (Dan Ackroyd) On 11 March 2015 at 21:44, Dmitry Stogov wrote: > Hi, > > Improvement ideas are welcome... Hi Dmitry, The idea was raised before of having both soft and hard limits for the memory consumption and time limits, and to trigger a user defined callback when the soft limit was reached. This would be beneficial in a couple of ways. i) It allows people to detect that their application is consuming more memory/time than they would like, but not enough to cause stability issues. This would be useful in production where you don't want to make a request fail unless you absolutely have to. ii) It allows them to decide exactly what action to take. Sometimes it's fine to terminate requests straight away, other times people would want to do some cleanup before terminating. Additionally being able to call gc_collect_cycles() in the callback would sometimes release enough memory to bring the memory used to back under the soft limit and so allow processing to continue. Ironically, this seems to be an issue when writing efficient PHP code. Due to the way the garbage collector only collects cycles rarely, if you have very large variables compared to typical code, you can easily encounter a situation where the total memory that is still being referenced is small, but there is still a huge amount being held in cycles. The code below shows this happening: With gc_collect_cycles called: peak memory = 786kB Without gc_collect_cycles called: Allowed memory size of 67108864 bytes exhausted i.e. 95% of memory allocated isn't being used and could be freed, but hasn't because the number of GC objects didn't reach 10,000 and so the gc_collect_cycles didn't kick in automatically. cheers Dan