Section 23.4. Compress Your Output


23.4. 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 itthis 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.



PHP in a Nutshell
Ubuntu Unleashed
ISBN: 596100671
EAN: 2147483647
Year: 2003
Pages: 249

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net