PDA

View Full Version : Checking whether your site is gzipped


jrobbio
06-07-03, 03:31 PM
Ever wondered why slashdot.org loads up so quickly yet it has masses of information? Well they use ModGzip to compress their files to become 73% smaller
Filesize: 39.8KB [10.7KB] html / text only

This can be done through the .htaccess, but more interestingly it can be done through php. Many forums have the settings in built to allow for compression to be used from levels 1-9 depending on how much strain they are willing to put on the server. There is a tutorial on how to do this here: PHP zlib compression (http://www.desilva.biz/php/zlib.html)

Once this is done, you can check how well your site is performing with the new compression at the gzip compression test (http://www.desilva.biz/gzip-test.php)

Rob

TheGreatOne
06-07-03, 03:40 PM
If you can get it to work brillaint. That page loads up sooooooooo quick! I think i will be using this if i can.

DuEy
06-07-03, 06:10 PM
How can it be done in .htaccess =?

TheGreatOne
06-07-03, 06:26 PM
That worked brillaint mate. Thank you very much!. Can this be done with cgi do you know???

Just to say how good.
-----------------------

Result The webpage is COMPRESSED / GZIPPED!

>> Savings: 82%

Filesize: 28.6KB [5.3KB] html / text only

Protocol/Status HTTP/1.1 200 OK

Date Sat, 07 Jun 2003 22:18:47 GMT

Server Apache/1.3.27 (Unix) (Red-Hat/Linux) Chili!Soft-ASP/3.6.2 mod_ssl/2.8.14 OpenSSL/0.9.6b PHP/4.1.2 FrontPage/5.0.2.2510

Content-Encoding gzip

Vary Accept-Encoding

X-Powered-By PHP/4.1.2

Content-Length 5072

Connection close

Content-Type text/html


---------------------


I would love to do this with my forums. So any more info would be welcome :)

jrobbio
06-07-03, 06:40 PM
See this post for information about the .htaccess: http://www.desilva.biz/forum/showthread.php?postid=2756#post2756

82%! that's the best improvement I've seen yet in fact that's amazing. I'd tried your site earlier on and it did seem kind of sluggish, tried it just now and its lovely.

By using the .htaccess files, the code doesn't need to be repeated over and oover again, but with a CMS the index file is sufficient, the same for forums.

One word of warning though, put any kind of flash file in its own folder and have a .htaccess file that turns off the compression or it won't work.

Rob

DuEy
06-07-03, 06:47 PM
thanks man. my clients just got a faster site =)

jrobbio
06-07-03, 06:59 PM
They'll be happier with you in the morning :') Just make sure you keep a check on the CPU intensity if its a busy site. It should reduce bandwidth costs around a third in many cases.

Rob

TheGreatOne
06-07-03, 07:33 PM
mate did you know if it can be done in cgi?

DuEy
06-07-03, 07:38 PM
You would probably need the gzip module for CGI

jrobbio
06-07-03, 07:42 PM
The answer is, I don't know. One of the best tutorials I've seen about it is here though: http://www.sitepoint.com/article/1029

Ahh found the answer and lucky for you it is a yes, http://packages.debian.org/stable/web/libapache-mod-gzip.html

Rob

Chris Boulton
06-07-03, 08:29 PM
Here is what we use in mybb for gzip page compression


function gzipencode($contents) {
global $HTTP_ACCEPT_ENCODING, $settings;
if(function_exists("gzcompress") && function_exists("crc32") && !headers_sent()) {
if(strpos(" ".$HTTP_ACCEPT_ENCODING, "x-gzip")) {
$encoding = "x-gzip";
}
if(strpos(" ".$HTTP_ACCEPT_ENCODING, "gzip")) {
$encoding = "gzip";
}
if($encoding) {
$level = $settings[gziplevel];
$gzdata = "\x1f\x8b\x08\x00\x00\x00\x00\x00";
$size = strlen($contents);
$crc = crc32($contents);
$gzdata .= gzcompress($contents, $level);
$gzdata = substr($gzdata, 0, strlen($gzdata) - 4);
$gzdata .= pack("V",$crc) . pack("V", $size);

header("Content-Encoding: $encoding");
header("Vary: Accept-Encoding");
header("Content-Length: ".strlen($gzdata));
$contents = $gzdata;
}
}
return $contents;
}


In mybb, nothing is directly echo'd out so we have a outputpage() function which does everything like the gzip compression.. This makes it possible so we dont have to have ob_start(); on each page..

The way the encoder is called is like this.


if($settings[gzipoutput] != "no") {
$contents = gzipencode($contents);
}

TheGreatOne
06-07-03, 08:34 PM
Brillaint! I can shove it in to my Ikonboard ;)

Chris Boulton
06-07-03, 09:17 PM
Maybe if you had a PHP to Perl converter! ;)

/me notes this is the PHP forum anyways... Ikon fans :rolleyes: (oops did i say that out aloud :p j/k)

TheGreatOne
06-07-03, 09:20 PM
nooooooooooooooooooooooo the code above that. God ya had to reply before me while i was replying. God wait in line :P

Psybadek
06-08-03, 02:53 AM
heh..

slashdot does load extrememly fast.. and i never realized that.

and mybb is fast to.... even with the msnplus forum that loads quick to

Chris Boulton
06-08-03, 03:38 AM
Yeah, i was actually more surprised at how well the old server that the Messenger Plus! forums are on handles myBB. The load has been over 1.0 once, most of the time it is below 0.5 which i think is good for a server like that that can handle up to 700 users online.

God wait in line :P

I'm sorry... next time i'll wait at the end and won't skip the queue :p

AbelaJohnB
06-08-03, 05:57 AM
For those of you not wanting to run your site through the link in the first post, here is some code (from Matt @SPF) that you can slap into a blank .php file.


function has_zend_optimizer()
{
ob_start();
phpinfo(INFO_GENERAL);
$info = ob_get_contents();
ob_end_clean();
return strpos($info, 'Zend Optimizer');
}
if (has_zend_optimizer()) {
echo 'Zend Optimizer: ENABLED';
} else {
echo 'Zend Optimizer: DISABLED';
}



It will automatically tell you if you have GZIP enabled or disabled.

DuEy
06-08-03, 06:02 AM
Originally posted by TheGreatOne
Brillaint! I can shove it in to my Ikonboard ;)

Ikonboard has this feature built in.

TheGreatOne
06-08-03, 06:23 AM
aye but its not the best!

SleeperZ
09-03-03, 06:52 PM
>> Savings: 85%

Filesize: 23.9KB [3.6KB] html / text only

I am so glad I found this thread, and so are my clients :-)

THANKYOU!