PDA

View Full Version : Using too much bandwidth?


retrogad
07-26-2005, 06:10 PM
Here's a tip to lower your bandwidth usage:

Put the following two lines into a text file:
zlib.output_compression = On
zlib.output_compression_level = 9
Save that text file as php.ini, and place this file in every public_html folder on your account. This will compress the PHP output pages; not only does this speed up download times, but it really takes a bite out of bandwidth usage. One of the primary features on my site is the forum (which means a lot of plaintext), and by adding those lines to my php.ini file, I've cut my text-only bandwidth usage from 1.14 GB/day to 0.42 GB/day! :D

Investme
08-06-2005, 09:33 AM
Can you tell me how this achieves compression? Does this compress whitespace only or images also? It looks like a VERY useful tool, especially if you have a lot of customers on low speed access.

retrogad
08-06-2005, 08:51 PM
Can you tell me how this achieves compression?

For any browser that supports it (most current browsers do), the server will compress all PHP output (any .PHP pages) before it sends the page to the user. It uses the standard gzip protocol, so it's like ZIPping a file on your computer.

Does this compress whitespace only or images also? It looks like a VERY useful tool, especially if you have a lot of customers on low speed access.

As far as I can tell, it only compresses PHP output, so it wouldn't cover any other files (images, .HTML pages, etc.). Since it's using the gzip protocol, though, it will compress whitespace. The gzip protocol works best on repeating patterns, which is why BBS pages compress so well (most BBS posts will contain the same words).

Gemma
10-13-2005, 07:50 AM
Well thanks for that tip, I've put it in my public_html directory.

downdll
10-27-2005, 06:49 AM
That's very good. I just did it as well.
Do you know i this work for html as well?

punkbyth
11-27-2005, 04:11 PM
they said they don't think it does.
i did this...it made my total file size from over 80000 bytes and it cut it down to the 70000 area.
are there any other tricks like this that you guys know of cause it'd be nice if i could make my site even smaller without removing stuff.

webprog
11-22-2006, 01:47 AM
Thanks for the tip retrogad. There are many ways to initiate output compression - I wasn't sure which one worked on SiteGround until I found your post.

I do want to mention that your setting of "9" is not generally recommended. You're using a lot of CPU for very little compression gain over a setting of 6 or 7. If you're a high traffic site, you might even set off the bad neighbor effect and get turfed if SG thinks your site is using too much CPU.

Finally, I'm playing around with the concept of using PHP to compress my .css files as well. I want to leave my .css files untouched, as my designer works with them, so I'm using URL rewriting to rewrite the requests for the CSS file into requests for a PHP script that just reads and outputs the CSS file (adding text/css Content-type in the header of course). With the output compression turned on as per your post, this should deliver the CSS to the browser compressed.

webprog
11-22-2006, 02:51 AM
Just a follow-up:

I have been successful in compressing output of CSS and JavaScript files to the browser. This has made the pages of a site I am working on load about twice as fast for me (I'm on dial-up) and that's significant.

The technique can be used to compress any type of static file in your site, though I don't think you'd see any real gains using it on images or flash, as those files are already compressed.

PM or contact me if you want to know more.

xeno|oreo
11-25-2006, 09:07 PM
Ah yes, I've been using PHP to compress my pages forever ^^

I personally use

ob_start('ob_gzhandler');

in the script before any output is sent to the browser. It dramatically compresses any code/text based data you're sending- but not other media such as sound, images, video, because those are already compressed.

Dekard
12-11-2006, 12:51 AM
so, the advantage is pretty obvious, lower bandwidth usage which will certainly help those on slower connections.

what are the downsides to this? where will it introduce incompatibilities? How much cpu time will it consume? why should I care when I've got 250g of bandwidth a month?

adragons
12-21-2006, 03:27 PM
zlib.output_compression_level = 9
is not a good trade off of cpu time vs bandwidth saved. 8 is better.

why should I care when I've got 250g of bandwidth a month?
Because your clogging the tubes!

Skash
12-22-2006, 12:06 PM
Here's a tip to lower your bandwidth usage:

Put the following two lines into a text file:
zlib.output_compression = On
zlib.output_compression_level = 9
Save that text file as php.ini, and place this file in every public_html folder on your account. This will compress the PHP output pages; not only does this speed up download times, but it really takes a bite out of bandwidth usage. One of the primary features on my site is the forum (which means a lot of plaintext), and by adding those lines to my php.ini file, I've cut my text-only bandwidth usage from 1.14 GB/day to 0.42 GB/day! :D

This doesn't work with phpnuke users, unless you can tweak your CMS to do so, I am doing that right as I type.

adragons
12-23-2006, 02:22 PM
Why wouldn't it work with CMS users? This tells the server to compress pages it sends that end with .php. Since CMS apps/programs are php, I fail to see why this wouldn't work.

Skash
12-27-2006, 02:08 AM
With some CMS they do have the script embedded already in the CMS and then it will conflict with it.

But not to worry, it will only put a little message up the top saying what went wrong and where you can fix it.

What happened with my CMS (phpnuke 8.0Patched) it just displayed that it already had the script and you can't compress twice, so I just jumped into the area that had the compression and upped the ratio, deleted the php.ini and all was fine after that.