PHP Howto compress page PDF Print E-mail
Written by Administrator   
Monday, 17 March 2008


In my never-ending quest to get my web pages to load super-fast, I chanced upon ob_gzhandler() one day while researching the uses of ob_start() in PHP.

What it does is, compress your html and web pages every time it's loaded onto a browser. Cool!

As usual, I will not get too technical on how it works but instead show you how to use it on your web pages like I have. And believe me, it's so simple you can even add it to your already existing pages without too much effort.

If it's not already obvious, you must be certain that you use PHP for your web pages and that your server supports it at least.

About PHP on your server
Then, you have to be sure that the version of PHP on your web server is extended with the zlib module. To find out quickly, just open NotePad and type in the following:

php:

           <?php  phpinfo();  ?>

Then save the file as phpinfo.php and upload it to your webserver. Once you view this page on your browser, look for zlib on the web page. If it's installed, one table on the page would look this:

On that same page, just note that the PHP version on your web server is 4.0.6 or higher otherwise you can't use this method to compress your web pages.

Sample code to compress your web pages
To compress your web pages this is basically how you would do it:

php:

<?php ob_start( 'ob_gzhandler' ); ?>
<html>

<head> </head>

<body>
                This web page is now COMPRESSED!

</body>
</html>

That's it!

or can use ini_set('zlib.output_compression', '1') in PHP code for force compression.





Digg!Reddit!Del.icio.us!Google!Live!Facebook!Slashdot!Netscape!Technorati!StumbleUpon!Newsvine!Furl!Yahoo!Ma.gnolia!Free social bookmarking plugins and extensions for Joomla! websites!
Last Updated ( Thursday, 27 March 2008 )