Page 1 of 2
[SOLVED]Compressing web pages
Posted: Thu Oct 28, 2004 9:16 am
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!

Re: Compressing web pages
Posted: Thu Oct 28, 2004 11:33 am
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.
Posted: Thu Oct 28, 2004 12:50 pm
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
Posted: Thu Oct 28, 2004 12:58 pm
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.
Posted: Thu Oct 28, 2004 5:15 pm
by Jean-Yves
Very many thanks. I'll pass this info on to the host server owner.
Posted: Fri Oct 29, 2004 2:47 pm
by Shendemiar
I tried this. How do i know if the files are beeing compressed?
Posted: Fri Oct 29, 2004 5:38 pm
by rehfeld
view the headers that the server sends
it will say
Content-encoding: gzip
Posted: Fri Oct 29, 2004 6:53 pm
by Shendemiar
rehfeld wrote:view the headers that the server sends
it will say
Content-encoding: gzip
Umm.. how do i do that?
Posted: Fri Oct 29, 2004 7:14 pm
by rehfeld
what browser u using?
Posted: Fri Oct 29, 2004 7:20 pm
by Shendemiar
Opera 7.x
I also have IE
Posted: Fri Oct 29, 2004 7:27 pm
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
Posted: Fri Oct 29, 2004 7:37 pm
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
Posted: Fri Oct 29, 2004 7:37 pm
by Shendemiar
Posted: Fri Oct 29, 2004 8:52 pm
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...
Posted: Fri Oct 29, 2004 8:57 pm
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...