[SOLVED]Compressing web pages

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
Jean-Yves
Forum Contributor
Posts: 148
Joined: Wed Jul 02, 2003 2:13 pm
Location: West Country, UK

[SOLVED]Compressing web pages

Post by Jean-Yves »

Could someone explain to me in simple steps the process of changing a web page so that it is compressed on the fly at the PHP end, and uncompressed on the fly at the browser end.

The server has been compiled with the "--with-zlib", although I am happy to use the ob_gzhandler() approach too.

I am stuck trying to get started, so to speak. I have read the manual pages for both approaches, but am still none the wiser?

Also, what is the typical compression ratio, and what kind of speed hit is there at the browser end?

A big thank you to whoever can help out there! :)
Last edited by Jean-Yves on Thu Oct 28, 2004 5:15 pm, edited 1 time in total.
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: Compressing web pages

Post by Weirdan »

Jean-Yves wrote: Also, what is the typical compression ratio, and what kind of speed hit is there at the browser end?
Compression ratio is usually about 3:1 for html and text documents. You shouldn't notice any serious perfomance degradation at browser end with modern hardware. ZIP is pretty fast compression algorithm.
rehfeld
Forum Regular
Posts: 741
Joined: Mon Oct 18, 2004 8:14 pm

Post by rehfeld »

you can do it in php, but setting it in apache is probably a better way for most people, that way .html files are compressed too. Plus, this way you dont need to edit any php files, ever.


put this in your . htaccess file. put the file in a directory, and everything in that directory will be compressed on the fly(for example, put in your doc root)

Code: Select all

php_flag zlib.output_compression on
php_value zlib.output_compression_level 1
you can set the level all the way up to 9 if you want, but the thing is, even level 2 will only have marginal improvement over level 1, but will consume more server resources. I find level 1 is the best setting(cost of server resources vs benefit), but it will depend on your servers load and capability. Level 1 still offers some extreme reduction in size, and the delay from the server compressing it is not noticable.

for example, on a page that lists all the available products, the html output goes from 15k, down to just 2.2k! very effective. works best on pages that have lots of repetitive html markup, a common example is a table design.

have fun
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post by kettle_drum »

I would also suggest to get your page code as clean as possible as there is no point in compressing if your code is already bloaty.
User avatar
Jean-Yves
Forum Contributor
Posts: 148
Joined: Wed Jul 02, 2003 2:13 pm
Location: West Country, UK

Post by Jean-Yves »

Very many thanks. I'll pass this info on to the host server owner.
Shendemiar
Forum Contributor
Posts: 404
Joined: Thu Jan 08, 2004 8:28 am

Post by Shendemiar »

I tried this. How do i know if the files are beeing compressed?
rehfeld
Forum Regular
Posts: 741
Joined: Mon Oct 18, 2004 8:14 pm

Post by rehfeld »

view the headers that the server sends

it will say

Content-encoding: gzip
Shendemiar
Forum Contributor
Posts: 404
Joined: Thu Jan 08, 2004 8:28 am

Post by Shendemiar »

rehfeld wrote:view the headers that the server sends

it will say

Content-encoding: gzip
Umm.. how do i do that?
rehfeld
Forum Regular
Posts: 741
Joined: Mon Oct 18, 2004 8:14 pm

Post by rehfeld »

what browser u using?
Shendemiar
Forum Contributor
Posts: 404
Joined: Thu Jan 08, 2004 8:28 am

Post by Shendemiar »

Opera 7.x

I also have IE
Shendemiar
Forum Contributor
Posts: 404
Joined: Thu Jan 08, 2004 8:28 am

Post by Shendemiar »

PHP_INFO from my root dir:

Directive Local Value Master Value
zlib.output_compression On Off
zlib.output_compression_level 1 -1
zlib.output_handler no value no value
rehfeld
Forum Regular
Posts: 741
Joined: Mon Oct 18, 2004 8:14 pm

Post by rehfeld »

niether of those can view headers (to my knowledge)

firefox can (get the web developers addition, youll like it)

i know ive seen websites where you can just type the url, and it will show you the headers
Shendemiar
Forum Contributor
Posts: 404
Joined: Thu Jan 08, 2004 8:28 am

Post by Shendemiar »

Shendemiar
Forum Contributor
Posts: 404
Joined: Thu Jan 08, 2004 8:28 am

Post by Shendemiar »

I have ieHTTPheaders installed and it shows lot of stuff, but no

Con*tent-encod*ing: g*zip

Instead i get this

Tran*sfer-En*coding: chu*nked

Dont mind the *'s i had to add them because i got internal server error while trying to post this...
Shendemiar
Forum Contributor
Posts: 404
Joined: Thu Jan 08, 2004 8:28 am

Post by Shendemiar »

rehfeld wrote:niether of those can view headers (to my knowledge)

firefox can (get the web developers addition, youll like it)

i know ive seen websites where you can just type the url, and it will show you the headers
I had Firefox, and tabbed browsing extension, but the extension was buggy.

Maybe i'll get it back...
Post Reply