home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  

Perl in a Nutshell

Perl in a NutshellSearch this book
Previous: 10.7 CGI.pm Reference Chapter 11 Next: 11.2 Installing mod_perl

11. Web Server Programming with mod_perl

A common criticism of CGI is that it requires forking extra processes each time a script is executed. If you only have a few hits an hour, or even a few hits a minute, this isn't a big deal. But for a high-traffic site, lots of CGI scripts repeatedly spawning can have an unfortunate effect on the machine running the web server. The CGI scripts will be slow, the web server will be slow, and other processes on the machine will come to a crawl.

The solution to this problem is mod_perl . mod_perl , written by Doug MacEachern and distributed under CPAN, embeds the Perl interpreter directly into the web server. The effect is that your CGI scripts are precompiled by the server and executed without forking, thus running much more quickly and efficiently. Furthermore, CGI efficiency is only one facet of mod_perl . Since mod_perl is a complete Apache/Perl hybrid, other benefits to mod_perl include:

  • Writing server-side includes in Perl

  • Embedding Perl code into the Apache configuration files

  • Writing complete Apache modules in Perl

11.1 Design of mod_perl

mod_perl is not a Perl module. It is a module of the Apache server, which is currently the most commonly used web server. With mod_perl , you can use Apache configuration directives not only to process CGI scripts much more efficiently, but also to handle all stages in processing a server request.

mod_perl embeds a copy of the Perl interpreter into the Apache httpd executable, providing complete access to Perl functionality within Apache. This enables a set of mod_perl -specific configuration directives, all of which start with the string Perl* . Most of these directives are used to specify handlers for various stages of the request, but not all. In addition, mod_perl lets you embed Perl code into your Apache configuration files (within <Perl> ... </Perl> directives) and allows you to use Perl for server-side includes.

It might occur to you that sticking a large program into another large program makes a very, very large program. mod_perl certainly makes httpd significantly bigger. If you have limited memory capacity, mod_perl may not be for you. There are several ways to minimize the size of Apache with mod_perl (which you can find in the mod_perl manpage or the FAQs), ranging from fiddling with Apache configuration directives to building Perl with reduced memory consumption.

Previous: 10.7 CGI.pm Reference Perl in a Nutshell Next: 11.2 Installing mod_perl
10.7 CGI.pm Reference Book Index 11.2 Installing mod_perl

Library Navigation Links

Copyright © 2001 O'Reilly & Associates. All rights reserved.