Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:28908 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 70999 invoked by uid 1010); 17 Apr 2007 19:58:50 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 70983 invoked from network); 17 Apr 2007 19:58:50 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 Apr 2007 19:58:50 -0000 Authentication-Results: pb1.pair.com header.from=shire@tekrat.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=shire@tekrat.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain tekrat.com from 204.15.23.157 cause and error) X-PHP-List-Original-Sender: shire@tekrat.com X-Host-Fingerprint: 204.15.23.157 www.sizzo.org Linux 2.6 Received: from [204.15.23.157] ([204.15.23.157:36518] helo=sizzo.org) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id FA/AD-14509-6D625264 for ; Tue, 17 Apr 2007 15:58:16 -0400 Received: from [172.21.211.84] (outcorp001.sctm.tfbnw.net [204.15.20.244]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) by sizzo.org (Postfix) with ESMTP id 8CDB8525D13; Tue, 17 Apr 2007 12:56:07 -0700 (PDT) In-Reply-To: <7cea347c0704160319x619b26d0s7716e35493e122c4@mail.gmail.com> References: <7cea347c0704160319x619b26d0s7716e35493e122c4@mail.gmail.com> Mime-Version: 1.0 (Apple Message framework v752.3) Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed Message-ID: Cc: internals@lists.php.net Content-Transfer-Encoding: 7bit Date: Tue, 17 Apr 2007 12:57:47 -0700 To: David Sklar X-Mailer: Apple Mail (2.752.3) Subject: Re: [PHP-DEV] Trapping "memory exhausted" error From: shire@tekrat.com (Brian Shire) I have code at Facebook that currently does something similar by catching fatal errors but there's a lot of gotcha's obviously that need to be handled properly when the engine is in this state. When possible we enable the printing of backtraces and other debug information, however you run the risk that instead of a nice backtrace you get a nice "Segmentation fault" error instead. This can be wrapped up in an extension and is all C code functionality, not exactly a soft memory limit so it's a little different than what's being discussed, but it might be another option to what you're looking for. I'm happy to share with a few initially who would find it useful/give feedback. -shire On Apr 16, 2007, at 3:19 AM, David Sklar wrote: > I am interested in being able to trap the (currently) fatal error that > results when memory usage exceeds the defined memory limit. > > I was thinking it could work as follows: > > - in addition to a memory_limit configuration directive, there could > be a "memory_limit_grace" configuration directive. This gets stored in > the struct _zend_mm_heap, along with the limit. > > - Also added to struct _zend_mm_heap is a "initial limit reached" flag > > - When zend_mm_safe_error() in Zend/zend_alloc.c is invoked under the > current conditions (memory_limit exceeded), it sets the "initial limit > reached" flag, adjusts the heap limit to the "memory_limit_grace" > value and throws some non-fatal error (or an exception if it is > feasible from here.) > > - When zend_mm_safe_error() is invoked and the "initial limit reached" > flag is already set, it throws the fatal error exactly as it does now. > > This "grace period" would provide a way to gracefully exit when a > memory limit is reached, but also has the hard limit still enforced so > that code which is supposed to be gracefully exiting doesn't chew up > too much additional memory. > > Is it feasible to adjust the heap limit and throw a non-fatal error > from within zend_mm_safe_error()? > > David > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php >