Embedding Perl into Apache
By Randal L. Schwartz
Back in my column titled "A Smart Picture Album" (see Web Techniques, January 1999), I demonstrated a nice little CGI "DirectoryIndex" handler that let users step through thumbnails of images on my site. Well, I now have 3500 images from my digital camera, totaling some 500MB available for download, and all those people wandering through the pictures were firing off quite a few CGI processes.
So, I decided to start using Perl embedded in my Apache Web server to reduce the number of new Perl compilations and separate processes, as well as give back not modified (304) return codes more often if a visitor were about to view a page he or she had seen before. Going one step further, I added a "reduce 50 percent" link for each picture that scales the image on the fly with ImageMagick's Perl interface (www.wizards.dupont.com/cristy/www/perl.html), because some people were complaining that the pictures were mostly too large.
Perl-enabled Apache (better known as mod_perl) is described at perl.apache.org, and is actively supported by Doug MacEachern and a volunteer crew distributed all over the world. Doug and fellow Web Techniques columnist Lincoln Stein have released the excellent book, Writing Apache Modules with Perl and C. For details about this publication, see www.modperl.com.
Special Handling
First, mod_perl needs to be told that we're going to have a special content handler for a section of the directory tree.