From: Scott K. <sc...@ki...> - 2003-06-21 02:17:45
|
You may or may not know that I have advocated using mod_gzip on apache servers to compress html and php on the fly to increase perfomance and page load times. Since Apache2 there has not been a reliable mod_gzip that is compatible (one is in the works though) But for those using Apache2 there is a reliable alternative. I am a linux advocate so I don't have explanations or examples for windows users. Sorry! To setup a linux machine to gzip html and php (you don't ever want to gzip images) you can follow my example. This example uses Red Hat Linux 9 (shrike) First: edit /etc/mime.typrd and add: application/x-httpd-php php Next: Add this to your /etc/httpd/conf/httpd.conf file: LoadModule deflate_module modules/mod_deflate.so Under the section where the modules are actually loaded! (This will only work if you actually have this module located in /etc/httpd/modules...if not you will need to recompile apache with the ./configure --enable-modules=all --enable-mods-shared=all --enable-deflate switch) Next scroll down a little farther in your httpd.conf file and add these lines somewhere after the AddHandler type-map var entry is where I have mine: <IfModule mod_deflate.c> SetEnv gzip-only-text/html 1 SetOutputFilter DEFLATE </IfModule> SetOutputFilter DEFLATE DeflateFilterNote ratio SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary SetEnvIfNoCase Request_URI \.(?:exe|t?gz|zip|bz2|sit|rar)$ no-gzip dont-vary SetEnvIfNoCase Request_URI \.pdf$ no-gzip dont-vary DeflateMemLevel 9 AddOutputFilterByType DEFLATE text/html application/x-httpd-php BrowserMatch ^Mozilla/4 gzip-only-text/html BrowserMatch \bMSIE !no-gzip !gzip-only-text/html Header append Vary User-Agent env=!dont-vary (I've put blank lines in between each entry because the second line starting with SetEnvIfNoCase should not be wrapped, it's supposed tobe on 1 line and my mailer may wrap it) Now save your httpd.conf file and restart apache and your webserver will automatically gzip all php and html files. NOTE: This method is much more efficient than PHP's built in ob_gzhandler so if you have any modules that have this hardcoded you will need to remove that or disable this option in your php.imi file. mod_deflate does ther gzipping much more efficiently and offers better performance. The DeflateMemLevel 9 is the maximum compression for mod_deflate and you can specify any interval from 1-9 to adjust for best performance and speed for your server. 6 is usually considered the best in terms of performance versus compression level. Despite the fact that the compression algorithm is not as effective as the one found in mod_gzip, using mod_deflate for Apache 2.0.x is still a quick and effective way to decrease the size of the files that sent to clients. Anything that can produce between 50% and 80% in bandwidth savings with so little effort should definitely be considered for any and all Apache 2.0.x deployments wishing to use the default Apache codebase. Once a stable mod_gzip is out for Apache2 I will update the list and create RPM's if nessessary. Enjoy! Zoom BTW: You can test you server to make sure it is actually gzipping no matter whether you use mod_gzip or mod_deflate by visiting http://leknor.com/code/gziped.php and typing in your server URL. To check if php is being gzipped make sure to use a URL to a php file such as http://yoursite/index.php |