Hudzilla.org - the homepage of Paul Hudson
Contents > Wish List | Report Bug | About Me ]

13     Output Buffering

This is NOT the latest copy of this book; click here for the latest version.

Output Buffering was introduced in PHP 4, so is not new in PHP by a long shot, and yet it still has yet to catch on amongst the masses despite the added flexibility it brings.

Without output buffering, PHP sends data to your web server as soon as it is ready - this might be line by line or code block by code block. Not only is this slow because of the need to send lots of little bits of data, but it also means you are restricted in the order you can send data. Output buffering cures these ills by enabling you to store up your output and send to send it when you are ready to - or to not send it at all, if you so decide.

Topics covered in this chapter are:

  • When to use output buffering

  • Manipulating multiple buffers

  • Incremental data flushing

  • Output compression


Chapter contents

13.1. Advantages
13.2. Performance Considerations
13.3. Getting started: ob_start(), ob_end_flush(), and ob_end_clean()
13.4. Reusing buffers: ob_flush() and ob_clean()
13.5. Stacking buffers
13.6. Flushing stacked buffers
13.7. Reading buffers: ob_get_contents()
13.8. Other OB functions: ob_get_length(), ob_get_level(), and ob_list_handlers()
13.9. Flushing output: flush()
13.10. Compressing output
13.11. URL rewriting: output_add_rewrite_var() and output_reset_rewrite_vars()
13.12. Summary
13.13. Exercises
13.14. Further reading
13.15. Next chapter



<< 12.8 Next chapter   13.1 Advantages >>
Table of Contents
Want to see this stuff in print? PHP in a Nutshell takes the core topics covered here, adds in thousands of edits from the editorial team and myself, and combines them to make an unbeatable reference for PHP programmers at all levels.



My latest book has hundreds more tips on how to use PHP, Apache, and MySQL, plus Perl, Python, shell scripts, performance tuning, and more!



Top-right shadow
 
Bottom-left shadow Bottom shadow

Comments from other readers
deathgod - 04 Jul 2008

Isn't output buffering null since php5? Because php5 reads the entire php file before sending it to the browser and it is only php4 that sends it line by line? I may be wrong but i remember reading that in chapter1. Can someone more informed please verify.



Add comment
Please note that by posting a comment here you are committing it to the public domain. This is important so that others can make use of your code themselves, and also so that I can incorporate helpful notes directly into the main text. Comments are limited to 2000 characters in length.

If you are reporting an error in the content, please tell me directly.

Your name/email address:
Your comment:
 
Now, in order to verify that you're a real person, please answer this simple question: what is five plus five?
The answer is:
(please write in
numbers, eg 19)


Top-right shadow
 
Bottom-left shadow Bottom shadow