php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #43042 Error handling when out of memory
Submitted: 2007-10-19 17:00 UTC Modified: 2007-10-19 19:15 UTC
From: thuejk at gmail dot com Assigned:
Status: Not a bug Package: Feature/Change Request
PHP Version: 5.2.4 OS: All
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: thuejk at gmail dot com
New email:
PHP Version: OS:

 

 [2007-10-19 17:00 UTC] thuejk at gmail dot com
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:
--------------
t@t ~/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


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-10-19 19:15 UTC] johannes@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

You should use a logfile for error messages. Changing the current behavior would break too many things.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Mon Dec 08 15:00:01 2025 UTC