Kenetix.net Home  
Home Discussion Forums Resources Utilities Resources More Stuff!
 
PHP

mod_gzip - Speed Up Your Page Load Time

Sunday, 19 October 2008 @ 09:47 PM

  One of the biggest turnoffs for visiting a website is slow page loading times. You may have the best looking site on the planet but if your site takes eons to load, no ones going to bother. At least I won't. Here's one solution to speeding up your website using gzip compression in PHP. This is especially useful for sites with lots of content/text.

Adding this line of code just before the opening <html> tags.

Quote:
if(isset($_SERVER['HTTP_ACCEPT_ENCODING'])){
if (strstr($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') && extension_loaded('zlib')) {
ob_start(array('ob_gzhandler',5));
ob_implicit_flush(0);
if (ereg("MSIE", $_SERVER['HTTP_USER_AGENT'])) {header('Content-Encoding: gzip');}
}
else{
ob_start();
ob_implicit_flush(0); // perform a flush operation, pushes content directly to user every output call
}
}
else{
ob_start();
ob_implicit_flush(0); // perform a flush operation, pushes content directly to user every output call
}


To test if your page uses gzip compression, visit this link:
http://whatsmyip.org/mod_gzip_test/
 
 

Article Info

 

Posted by: Kenetix

Topic: PHP

Length: 141 Words

Comments: 3

Rating: 4 stars

Votes: 4

RSS Syndication: Enabled

 
 

Rating

 

Current Rating


(4 stars)
Excellent
Good
Average
Poor
Terrible

 
 

Article Options

 
Save to NewsboxSave to Newsbox
Print ArticlePrint Article
Add To FavoritesAdd To Favorites
Digg ArticleDigg Article
 
 

Comments List

 
Ive been trying to get this to work with phpnuke for a while now and never have any success. I think its a broswer issue though because most sites that use it arent working for me.

Posted By Posted By: undergrew | Date Date: Saturday, Nov 08 2008, 10:01 AM

yea the browser has to support Gzip in order for this to work

Posted By Posted By: Kenetix | Date Date: Monday, Nov 10 2008, 00:31 AM

I realised that so I'm looking into the server side functions. Those are cross browser compatible right? Did you check your pms?

Posted By Posted By: undergrew | Date Date: Wednesday, Nov 12 2008, 16:56 PM

 

Post A Comment

 
You need to be logged in to submit a comment. Click the button below to login and return to this page.

 
Back To Top