php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #31905 Memory Limit bypasses set_error_handler
Submitted: 2005-02-09 19:00 UTC Modified: 2005-02-09 22:34 UTC
From: ceo at l-i-e dot com Assigned:
Status: Not a bug Package: *Programming Data Structures
PHP Version: 4.3.10 OS: FreeBSD 4.10-STABLE
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 this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: ceo at l-i-e dot com
New email:
PHP Version: OS:

 

 [2005-02-09 19:00 UTC] ceo at l-i-e dot com
Description:
------------
set_error_handle seems totally ineffective for Memory Limit settings.


Reproduce code:
---------------
ini_set('memory_limit', '32K');
ini_set('error_reporting', 0);
echo "Memory Limit: ", ini_get('memory_limit'), "\n";
echo "Memory Used: ", memory_get_usage(), "\n";
function error_handler($error, $message, $file, $line){
  echo "Error ($error) in $file:$line - $message\n";
  return true;
}

set_error_handler('error_handler');
trigger_error("Test", E_USER_NOTICE);

$str = str_repeat('a', 1024);
while (true){
  echo '.';
  flush();
  $str .= $str;
}
echo "\nMade it!\n";


Expected result:
----------------
I expected to see the same error message PHP usually reports, more or less, and then "Made it!".


Actual result:
--------------
-bash-2.05b$ php test.php 
Content-type: text/html
X-Powered-By: PHP/4.3.10

Memory Limit: 32K
Memory Used: 13432
Error (1024) in /www/l-i-e.com/web/test.php:12 - Test
....-bash-2.05b$ 

Note that my test error message comes out, and PHP continues, but upon reaching memory limit, it just dies, with no call to my error handler.
:-(

I'm not sure that a soft limit imposed should necessarily be considered non-recoverable...

Though I can see how even trying to call the function at that point is problematic, in terms of not triggering the error again in an infinite loop...

Still, it would be nice to be able to trap this and do something useful rather than just die, if possible.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-02-09 22:34 UTC] iliaa@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

memory limit error is a fatal E_ERROR that cannot be captured by php's error handler.
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sun Oct 17 10:03:37 2021 UTC