|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2006-04-26 00:45 UTC] mailslot at mac dot com
Description:
------------
I encountered this problem while debugging an exception logging class.
Infinite recursion problems are a coding mistake, but I've never seen one take down Apache before. Apache will grow in size until virtual memory starts swapping. The CPU will be at 100% and eventually, appears to halt. Limits, obviously, are not being used... yet.
Reproduce code:
---------------
<?php
class Eggception extends Exception
{
public function __construct($ex)
{
parent::__construct($ex);
try {
// let's say that a database object throws derived Eggception
throw new EggceptionSubclass('It happens');
// this is valid (not infinitely recursive)
//throw new Exception('It happens');
} catch (Exception $e) {
// should swallow exception, right?
// not before a never-ending recursive bomb
}
}
}
class EggceptionSubclass extends Eggception {}
// the following causes a runaway process (memory leak &
// CPU spike) with Apache 2.0.55 and PHP 5.1.2
// rather quickly, all server resources become exhausted
// without proper process limits, potentially crashing the
// entire machine.
throw new Eggception('Exception Bomb');
?>
Expected result:
----------------
A timeout after a large CPU spike... perhaps a stack overflow error.
An exception recursion counter that kills a script whenever it's 1,000 layers deep in an exception stack... that would be great.
Actual result:
--------------
The process (PHP or Apache, depending on which are used to execute the script) will consume as much memory allowed while pegging the CPU at 100% utilization. Kill -9 works fine.
Workarounds include ulimit and softlimit.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Nov 06 08:00:01 2025 UTC |
It means you didn't enable memory limit. ------------ php -r 'function foo() { $a = "text"; foo(); }; foo();' Fatal error: Allowed memory size of 2097152 bytes exhausted at ..Zend/zend_ptr_stack.h:59 (tried to allocate 137216 bytes) in Command line code on line 1