I am always looking for ways to make my websites faster, and I know that everyone loves a fast website. Lucky for me I stumbled across this PHP function ob_gzhandler().
Basically what it does is compresses your PHP/HTML code every single time a users web browser loads your site. How cool is that?

To use it all you have to do is be using the .php extension on your pages, if you are, lets get it working…

Check Your Server

First things first, we better check our server will let us run it. To do this theres a really easy function in PHP called “PHPinfo”. Just open notepad and make a file with the following code in it, then save as phpinfo.php

<?
phpinfo();
?>

Now save and upload this to your site and go to http://yourdomain.com/phpinfo.php
What you are looking for is “Zlib Support” if it says enabled, we are good to go! Also please check you are running PHP 4.0.6 or higher or this method will not work for you.

How to compress your page!

Now to compress your page all you have to do is put this code before your and tags in your pages, so the top of your code should look like this…

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

And we’re done!!! That was really easy huh?
You should notice a large speed increase in your site, and it will of course also make your site use much less bandwidth. It wont effect any of your images as they are already compressed themselves.

1 Star2 Stars3 Stars4 Stars5 Stars (2 votes, average: 5 out of 5)
Loading ... Loading ...
| Discuss in our Forums