Tuesday
10
Feb 2004

provide gzip for my apache/php based blog?

(10:10 pm) Tags: [How do I...]

Since Alex and I are trying to be good netizens, and we want to spare the precious bandwidth, we implemented gzip support for most of our websites. Since we are using Apache and PHP with the great b2 rewrite that is WordPress, I want looking for documentation.

If you are using Apache 2.0, follow along, this is relatively painless. Reading the great documentation for Apache 2.0 mod_deflate, just add the recommended configuration to your httpd.conf and restart apache.

Add this to your httpd.conf
AddOutputFilterByType DEFLATE text/html text/plain text/xml
<Location />
    # Insert filter
    SetOutputFilter DEFLATE
 
    # Netscape 4.x has some problems…
    BrowserMatch ^Mozilla/4 gzip-only-text/html
 
    # Netscape 4.06-4.08 have some more problems
    BrowserMatch ^Mozilla/4\.0[678] no-gzip
 
    # MSIE masquerades as Netscape, but it is fine
    # BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
 
    # NOTE: Due to a bug in mod_setenvif up to Apache 2.0.48
    # the above regex won’t work. You can use the following
    # workaround to get the desired effect:
    BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html
 
    # Don’t compress images
    SetEnvIfNoCase Request_URI \
    \.(?:gif|jpe?g|png)$ no-gzip dont-vary
 
    # Make sure proxies don’t deliver the wrong content
    Header append Vary User-Agent env=!dont-vary
</Location>

See how easy this is when someone else did most of the work? :) Now we test it. Since Ted has done the legwork on this, all we need to do is ask Leknor if everything is good by navigating here to see if we are now gzipped.

Summary: It is not terribly hard to add gzip support to your blog entries (or your entire website), as long as you ask the web wizards for the magic incantations. YMMV.

Popularity: 10%

Comments: Comments Off

add gzip support into php 4?

(8:57 pm) Tags: [How do I...]

Since I am archiving all web access logs as gzipped files, we needed to read them using our custom php script. Well, the fine documentation on php.net tells you exactly how to do it, if only your php install had it enabled. What to do? Just add the directive to your configure script, and you are good to go:

./configure (all my directives) –with-zlib=/usr; make; make install; apachectl restart

Then, in your php, just replace something like this:

$fd = fopen($todaylog, “r”);

with:

$fd = gzopen($todaylog, “r”);

How hard do we have to make it in java land? I leave that 30+ lines of code as an excercise to the reader.

Popularity: 11%

Comments: Comments Off