I've got a handmade ORM in PHP that seems to be bumping up against an object limit and causing php to crash. Here's a simple script that will cause crashes:
<?
class Bob
{
protected $parent;
public function Bob($parent)
{
$this->parent = $parent;
}
public function __toString()
{
if($this->parent)
return (string) "x " . $this->parent;
return "top";
}
}
$bobs = array();
for($i = 1; $i < 40000; $i++)
{
$bobs[] = new Bob($bobs[$i -1]);
}
?>
Even running this from the command line will cause issues. Some boxes take more than 40,000 objects. I've tried it on Linux/Appache (fail) but my app runs on IIS/FastCGI. On FastCGI this causes the famous "The FastCGI process exited unexpectedly" error.
Obviously 20k objects is a bit high, but it crashes with far fewer objects if they have data and nested complexity.
Fast CGI isn't the issue - I've tried running it from the command line. I've tried setting the memory to something really high - 6,000MB and to something really low - 24MB. If I set it low enough I'll get the "allocated memory size xxx bytes exhausted" error.
I'm thinking that it has to do with the number of functions that are called - some kind of nesting prevention. I didn't think that my ORM's nesting was that complicated but perhaps it is. I've got some pretty clear cases where if I load just ONE more object it dies, but loads in under 3 seconds if it works.