Debugging Output Buffering Being Disabled

If you are confused as to exactly which bit of code is killing your output buffer in PHP then you might love this little trick. Combined with Xdebug it can get you to the root of the problem quickly and easily.

The trick involves using the callback function capability of ob_start.

Firstly you need to make a callback handler, for example:

function ob_callback(){
    echo 'wtf';

Then in your IDE, set a break point on the echo line. If you aren’t using Xdebug, you could do something like this instead:

function ob_callback(){
    echo '<h1>Output Buffer Has Been Killed</h1><pre>';

Then where you are starting your output buffer, simply pass in the function name as a parameter like so: