Home > PHP > How to improve PHP page downloads

How to improve PHP page downloads

October 20th, 2007 admin Leave a comment Go to comments

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

Categories: PHP Tags:

Warning: session_start(): Cannot send session cookie - headers already sent by (output started at /home/sunilb/www.sunilb.com/wp-content/plugins/all-in-one-seo-pack/aioseop.class.php:245) in /home/sunilb/www.sunilb.com/wp-content/plugins/mycaptcha/MyCaptcha.php on line 41

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/sunilb/www.sunilb.com/wp-content/plugins/all-in-one-seo-pack/aioseop.class.php:245) in /home/sunilb/www.sunilb.com/wp-content/plugins/mycaptcha/MyCaptcha.php on line 41
  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
    typicalprogrammer.com

  1. No trackbacks yet.
Enter this code to leave comment (Sorry, but bots get me crazy :) )