Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP output buffering - sounds like a bad idea, is it?

Just want to pick the experts' brains on php output buffering. There are times when I've wanted to implement it for one reason or another, but have always managed to rearrange my code to get around it.

I avoid using it because it sounds like it'll cost resources. I mean, if they can offer the coder such wonderful flexibility, why don't they always buffer output? The only answer I can come up with is: because not buffering it saves tremendous resources, and with good coding practice you shouldn't need it.

Am I way off here?

like image 392
Aaron Avatar asked Oct 12 '09 20:10

Aaron


People also ask

What is PHP output buffering?

Output Buffering is a method to tell the PHP engine to hold the output data before sending it to the browser.

What does it mean when output is buffered?

An output buffer is a location in memory or cache where data ready to be seen is held until the display device is ready. Buffer, Memory terms, Output.


1 Answers

From my experience, there isn't a significant impact on performance. I also can't find consistent answers on the subject -- some people claim that there is barely any hit against performance, while some say that there is a minor but significant effect. There is even a comment on php.net suggesting that buffering increases performance as compared to multiple output functions, not that I've verified that or anything.

I think the question of whether or not to buffer has more to do with the intended use of your application. Buffering makes a lot of sense if you want to compress the output before sending it, or if you want to control exactly when and where the output takes place in your code. Since it doesn't take that much effort to add buffering, you may as well try it out -- it should be relatively easy to remove it if you need to.

like image 84
Brett Coburn Avatar answered Sep 23 '22 03:09

Brett Coburn