From: thuejk at gmail dot com
Operating system: All
PHP version: 5.2.4
PHP Bug Type: Feature/Change Request
Bug description: Error handling when out of memory
Description:
------------
I have a PHP production setup where errors are automatically reported to
me via email, by using a custom error handler.
However, when PHP reaches it's memory limit the custom error handler is
disabled. As a result, I may not be notified of OOM errors.
It would be nice if PHP did one of two things:
1) Emit an E_WARNING the first time the script reaches 99% (or something
like that, maybe configurable) of memory_limit.
2) When the program reaches the memory limit the first time, add fx 1MB
(perhaps user configurable) to the memory limit, emit an OOM E_WARNING, and
let the custom error handler handle the error. The next time the memory
limit is reached then really die.
I would prefer 1)
Reproduce code:
---------------
<?php
function custom_error_handler($error_code, $error_string, $filename,
$line, $symbols) {
die("This is the custom error handler");
}
set_error_handler('custom_error_handler');
$i = 0;
$a = Array();
while (true) {
$a[$i] = $i++;
}
?>
Expected result:
----------------
It would be nice if my custom error handler was allowed to run.
Actual result:
--------------
[EMAIL PROTECTED] ~/php_oom> php test.php
Fatal error: Allowed memory size of 16777216 bytes exhausted (tried to
allocate 35 bytes) in /home/thue/php_oom/test.php on line 10
--
Edit bug report at http://bugs.php.net/?id=43042&edit=1
--
Try a CVS snapshot (PHP 4.4):
http://bugs.php.net/fix.php?id=43042&r=trysnapshot44
Try a CVS snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=43042&r=trysnapshot52
Try a CVS snapshot (PHP 5.3):
http://bugs.php.net/fix.php?id=43042&r=trysnapshot53
Try a CVS snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=43042&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=43042&r=fixedcvs
Fixed in release:
http://bugs.php.net/fix.php?id=43042&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=43042&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=43042&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=43042&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=43042&r=support
Expected behavior: http://bugs.php.net/fix.php?id=43042&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=43042&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=43042&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=43042&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=43042&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=43042&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=43042&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=43042&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=43042&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=43042&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=43042&r=mysqlcfg