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


--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to