Continue output buffering despite aborted connection

Here at Zend we strive to find new ways to keep PHP developers sharp and on the leading edge of development bast practices. To that end, we have created our first “JumpStart” class, PHP7 JumpStart. A JumpStart class is different from our normal format. It is only one day and there are no interactive exercises. JumpStart classes are designed to help existing developers quickly come up to speed on a given topic. This post was extracted from our PHP7 JumpStart to show you what you can expect.

One of the RFCs included in PHP7 is “Continue output buffering despite aborted connection” contributed by Michael Wallner.

Continue output buffering despite aborted connection title slide.


This RFC is to fix an issue introduced in PHP 5.4 during the re-write of the output buffering layer.

Slide describing the problem with output buffering introduced in PHP 5.4.


The problem is that if you set ignore_user_abort=true, and the connection was aborted, the script would finish as designed. However, if you had an output buffer handler defined, it would be skipped.  This not only affects userland code though, it also affects several built-in functions.

Slide listing the internal language functions that are affected by this bug.

Again, it only affects them if ignore_user_abort is set to true and the connection is aborted.

Slide describing the solution that PHP7 implements to fix output buffering.

The solution in this case is simple, make it work the way it was supposed to and the way it had up until 5.4. In PHP 7, if you have a callback defined for output buffering, and you have ignore_user_abort=true then upon an abort, the script will finish and the output will be handed to the callback. The results will still be discarded as the connection has been aborted, but if you are doing processing inside of the callback, it will still happen.

Sample code to show the potential problem.

In this simple example, we use output buffering to process a series of numbers and output FizzBuzz. If the connection is aborted during the loop in PHP 5.4-5.5, make_fizzBuzz would never be called. In this case, since we calculate each run on the fly, the results would not be bad. However, if after calculating FizzBuzz, we stored the results in a file, and read that file in if it existed next time before even hitting the for loop, the results would be incomplete.

Slide discussing any potential backwards compatibility breaks with code written prior to PHP7.

Since behavior is changing from 5.4-5.5. there is a very slight chance for a BC break. If your code actually depends on this behavior, it will break. However, since this was introduced in 5.4 and the result is incomplete processing, chances are good that most developers have not built code depending on this behavior.

Join us for PHP7 Jump Start

Want to learn more? Join us for PHP7 JumpStart. In a single day we will cover every new function and feature that is scheduled for inclusion in PHP7.

Get a jump start on PHP7.