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