How to improve PHP page downloads

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.


Steps:

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

<?php
ob_start(”ob_gzhandler”);
?>

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:

<?php
ob_end_flush();
?>

That’s it, you are done.

Let me know if you have any questions or comments

Your email:  
Subscribe Unsubscribe  

del.icio.us Reddit Slashdot Digg Facebook Technorati Google StumbleUpon Windows Live Furl Netscape Yahoo Bloglines Bookmark.it Ask Spurl Diigo

One Response to “How to improve PHP page downloads”

  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
    typicalprogrammer.com

Leave a Reply

Top Internet blogs Programming Blogs - Blog Catalog Blog Directory TopOfBlogs Technology blogs Top Blog Topsites List