How to Enable gZIP Compression For Your Web-pages with PHP January 18, 2012Posted by tournasdimitrios1 in PHP.
Web-pages nowadays include a lot of client-side scripting code (for example JQuery and it’s supported plugins ) that affect the latency and probably influence search engine rankings for these pages . Latency is a big fancy word that simply means the amount of time between when something was started and when you can see its effects . A search engine may look at a range of information , probably latency is one of them , to make decisions whether it will visit and index pages on the Web , how it might rank those pages in search results , and how it may classify those pages .
PHP again has a solution for the aforementioned latency factor , the gZIP compression utility . It reduces the size of you files , improves the performance of your website and highly decreases its loading time . For complex websites it is highly recommended to enable it . The only requirement is that your server has the zLib extension enabled , just run a phpinfo() to verify that it’s enabled .
Some applications have internal support to compress their pages . For example , in Joomla you can turn on the gZIP compression from Global Configuration > Server > gZIP Page Compression set to ON . If you are not using a web application that has internal methods for enabling the compression, you can add the following line at the top of your php files :
<?php if (substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')) ob_start("ob_gzhandler"); else ob_start(); ?>
The results can be measured , by FF’s Firebug plugin or Chrome’s developer console , select the network tab and reload the page . Even a gain of 0.3 second on the latency factor / page may not sound a big deal but the overall benefit of your server on a 20K/day visitors website could be said it’s worth .