Skip to Main Content
PHP in a Nutshell
book

PHP in a Nutshell

by Paul Hudson
October 2005
Intermediate to advanced content levelIntermediate to advanced
372 pages
11h 35m
English
O'Reilly Media, Inc.
Content preview from PHP in a Nutshell

Compress Your Output

HTML is a very wordy format, which means there's a lot of duplication in the form of HTML tags, and in the main body text. Furthermore, by default, PHP will send text to Apache as soon as it is ready, which results in less efficient transfer of data.

The solution is to enable output buffering, and to use gzip compression for the buffers. Not all clients support receiving compressed content (every browser made in the last five years will), and to handle that, PHP will only compress data if the client can support it—this means you can enable compression and not have to worry about old clients, because PHP will not send them compressed data.

The best way to use output buffering is to use the commands shown in Chapter 11. However, if you don't want to change your scripts, open up your php.ini file and set output_buffering to 1 and output_handler to ob_gzhandler(without the quotes). You'll find those values already set in your php.ini already, so just change the existing values. You should check your phpinfo() output to make sure output buffering is enabled correctly.

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

PHP Cookbook

PHP Cookbook

Eric A. Mann
Programming PHP

Programming PHP

Rasmus Lerdorf, Kevin Tatroe
Learning PHP

Learning PHP

David Sklar

Publisher Resources

ISBN: 0596100671Errata Page