Advantages

Forget having to send your cookies near the start of your page! Output buffering lets you "send" cookies at any point your script - although, of course, it just stores the cookies separately to the HTML data then sends them together at the end, in the correct order. The bulking together of data also provides quite a performance improvement - PHP literally hangs on to all data until you instruct it to send, at which point all data is sent in one chunk.

Once you are using output buffering, you can compress content before you send it. Due to the fact that HTML is lots of very simple, repeating tags, and normal writing on a site is also very easy to compress, compressing your pages can make a big dent in the amount of bandwidth your site (and your visitor!) uses.

One final advantage is that output buffers are stackable, meaning that you can have several buffers working on top of each other, sending to output whichever ones you want.

 

Want to learn PHP 7?

Hacking with PHP has been fully updated for PHP 7, and is now available as a downloadable PDF. Get over 1200 pages of hands-on PHP learning today!

If this was helpful, please take a moment to tell others about Hacking with PHP by tweeting about it!

Next chapter: Performance Considerations >>

Previous chapter: Output Buffering

Jump to:

 

Home: Table of Contents

Copyright ©2015 Paul Hudson. Follow me: @twostraws.