Web Design and Development
Recently, we wrote an article which outlined 32 things that webmasters can do to speed up their websites. One item that we mentioned was the use of GZIP compression to speed up the delivery of web pages. Most people, however, hadn't heard of GZIP, so we were contacted for methods to add it to websites.
In this article, we show how to use GZIP with PHP on a Linux Apache web server.
Most web hosts compile PHP with support for GZIP. In fact, we have yet to find a Linux web host which does not support GZIP compression.
If you are in doubt about your web host, simply contact them and inquire about GZIP.
Adding GZIP to your website is very simple. In fact, all you have to do is add one simply line of code to your php pages.
The code snippet below needs to be placed as the first line in your document, before any other code.
<?php ob_start("ob_gzhandler"); ?>
And that's it. Now your web pages will be served more quickly.
You might be wondering how that little line of code can make your web pages more efficient. And given that it is a PHP function, you might wonder why the added processing time does not affect the page load. However, GZIP is proven effective.
More information about GZIP can be found in the PHP.net manual.Tags: compression software, gzip, load time