<<< the Charles Hotel Rocks

Home

Saturday, May 01, 2004 11:17 PM >>>


nph and mod_gzip

Saturday,  05/01/04  08:14 PM

If you write nph CGIs, be sure to exclude them from mod_gzip.  That's the message of this post; feel free to skip the rest if this is geek to you.

This is only of esoteric interest to 99.99% of you, but posting it here this is the best way for me to find it again.  Also this wasn't anywhere on the web - that Google knew of, anyway - so now maybe someone else who's looking will be able to find it, too.

Today I wrote an nph CGI, and it wasn't working.  After a lot of poking around and trying things, I finally realized why it didn't work: I have mod_gzip enabled!  Of course.  The answer was to disable mod_gzip for nph CGIs, with the following apache directive:

mod_gzip_item_exclude file nph.*.cgi$

In order to perform its compression mod_gzip has to buffer all the output from a CGI, thereby negating the "pass everything through in realtime" behavior of an nph CGI.

For those who are wondering, nph means "non-parsed headers".  Any CGI program whose name begins with "nph-" is assumed to use "non-parsed headers", which means apache will simply pass through the output of the CGI directly to the browser.  In such cases the CGI must generate all the HTTP headers, even the "HTTP/1.0 200 OK" response.  This is most useful for CGIs which generate ongoing output from some long-running process, such as progress messages or a debugging log.

And for those who are wondering, mod_gzip is an apache module which enables LZW compression for output pages to browsers which support it.  This enables a reduction of bandwidth of over 50%, and I highly recommend it (see my site optimization article from a year ago for more information).