Home > PHP > How to improve PHP page downloads

How to improve PHP page downloads

October 20th, 2007

I wanted to play with the buffering capabilities of PHP and tested it on my site http://www.careercurry.com.

I wanted to use it to improve the site performance and download times for my site and hence implemented GZIP compression on the home page and my article pages.

To improve your site performance implement the following steps on your pages. I recommend creating a copy of a page that you want to test and implement changes on the copy before you implement it on the actual page. Also try these changes on one page before you go live on the entire site.


1. In the beginning of your script write the following code:


In the above code, ob_gzhandler is a function provide by PHP which accepts a string as input and returns gzipped data. Therefore, you set ob_gzhandler() as a call back function to ob_start() function. The call back happens after a call to ob_end_flush() is made in the script.

2. At the end of your script; write the following code:


That’s it, you are done.

Let me know if you have any questions or comments

Categories: PHP Tags:
  1. October 23rd, 2007 at 02:22 | #1

    You can also set zlib.output_compression On in the php.ini file, rather than add the code to all of your scripts. If you aren’t allowed to change the php.ini file on your hosting provider you may be able to change it in a .htaccess file.

    If you’re using Apache and have privileges it’s probably better to enable compression there rather than doing it in PHP.

    Greg Jorgensen

Comments are closed.