OutputCompression

Summary: Use zlib output compression to make pages load faster
Version: 8 May 2005
Prerequisites: This recipe is independent of the PmWiki version
Status:
Maintainer: Anno

Question

How do I make my site pages display faster?

Answer

The answer is zlib output compression.

Enabling the zlib output compression can speed up the load times considerably(up to 7x and more), particularly on pages which are comprised mostly of html code without pictures (as is the case with most pages generated by pmwiki)

These directions apply for Apache servers with PHP, and the zlib compression module installed, which is the case with the majority of the servers.

To enable the compression , you just have to add the following 2 lines to the .htaccess file which resides in the www directory of the server. If there is no such file, create it:

 php_flag zlib.output_compression on
 php_value zlib.output_compression_level 2 

That's it. Providing the server supports it, you should now experience considerable diference in how fast the pages are displayed.

In order to check whether the compression works and see the compression ratio visit this page: http://www.port80software.com/products/httpzip/compresscheck or http://www.gidnetwork.com/tools/gzip-test.php .

If the server displays an error message after you added those 2 lines then your server doesn't support it in this simple way. In this case remove the above 2 lines from the .htaccess file and upload the file again. Ask your server administrator if he can enable the compression.

Answer 2

The method described in Cookbook-V1/ReduceBandWidth still works for pmwiki version 2.
This method works better for shared hosting situations where users cannot modify php.ini.

Depending on the compilation of php on your host (PHP compiled with "--with-zlib") this might be as easy as adding:
ob_start("ob_gzhandler");
as first line to your local/config.php or local/farmconfig.php script.

NOTE:

To prevent conflicts if zlib is already activated, and since using zlib.output_compression is preferred over ob_gzhandler() better use the following variant:

if (	!@ini_set('zlib.output_compression',TRUE) &&
	!@ini_set('zlib.output_compression_level',2)) 
		ob_start('ob_gzhandler');

Notes

Contributors

Anno May 08, 2005, at 06:22 AM

Comments

See discussion at OutputCompression-Talk

User notes? : If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki.