Is using output buffering considered a bad practice?

Are ob_start / ob_get_clean() considered bad practice by php programmers in general?

Are there any disadvantages of output buffering?


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.

PS: also I found this topic about output buffering.

链接地址: http://www.djcxy.com/p/34688.html

上一篇: 我不能setcookie“头已经发送”

下一篇: 是否使用输出缓冲被认为是一种不好的做法?