Bypassing Output Buffering in PHP

I’ve been developing with PHP for over a decade and I just love it when I learn a new trick.

Perhaps you are working on a command line script and want some feedback, but you’re output buffering to generate a fancy report (or something).  You can bypass the output buffering with this little trick

<?php

ob_start();

echo "BOOM!\n";

fwrite( STDOUT, "You smell funky\n" );

echo ob_get_clean();

Result:

You smell funky
BOOM!