Is using output buffering considered a bad practice? [closed] Is using output buffering considered a bad practice? [closed] php php

Is using output buffering considered a bad practice? [closed]


It's actually a good practice. Speed up data transfer


Output buffering in some circumstances is almost mandatory. With PHP as soon as you output something back to the user, headers are sent. Therefore if you get partway through processing a page and something happens that requires a header being sent you cant unless buffering is turned on. Otherwise you get the dreaded "Cannot modify header information – headers already sent".

Some will tell you you shouldn't code that way. humbug I say!

With buffers turned on your code can be more flexible.


output buffering is NOT a bad practice. For example it can speed up the loading of your website by using GZIP compression(although if possible it is better to do this inside .htaccess).

<?php     if (substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip'))         ob_start("ob_gzhandler");     else         ob_start(); ?>

Disadvantages: I don't know. Good question.

P.S: also I found this topic about output buffering.