The biggest PHP backtrace in the world

I was debugging a PHP segfault in a unit test with Andrei a while back, and it produced what we believe is the largest PHP backtrace ever.

I’ve seen some pretty massive memory consumption with PHPUnit; I have a test suite that needs 1.2gb of RAM to run. The test I was looking at was dying with an OOM at that level, so I turned memory_limit up to 2.5gb. At that point it stopped OOMing and started segfaulting.

When the interpreter crashes, I hand problems off to Andrei. He took a look and came back with the answer.

When the test ran, an exception was thrown, then caught and logged with print_r($e, true). That true tells PHP to return the pretty-printed value as a string, rather then outputting it. Internally, PHP implements this by enabling otuput buffering, calling print_r() normally, then shutting down OB and returning the captured buffer.

Now, the problem here is that the output buffer is limited to two gigabytes, since it’s accessed through a signed 32-bit pointer. The backtrace was 4.1gb, so it overflowed the buffer and crashed PHP.

2009/09/20
Previously On Atomized:

Participate