Improving Performance with mod_perl
Test Your mod_perl Configuration
Each time you modify the configuration file, as in the preceding section, you must restart Apache. (See Chapter 2 for instructions on doing so.)
Do that right now, and then you'll be ready to test your setup. To begin, request the perl-status "page" from your site:
http://www.snake.net/perl-status
In your browser, you should see something similar to Figure 3.1, where the initial part of the display shows some overall configuration information and the items below the line provide links to pages listing more specific information about mod_perl itself. Select a few of the links to get a feel for the kinds of information they provide.
Next, create the following short script in the cgi-bin directory (that's right, cgi-bin, not cgi-perl):
#! /usr/bin/perl
print "Content-Type: text/html\n\n";
print "<html><head><title>Script Environment</title></head><body>\n";
print map { "$_ = $ENV{$_}<br>\n" } sort (keys (%ENV));
print "</body></html>\n";
Name the script perltest.pl, make it executable, and request it through your browser (http://www.snake.net/cgi-bin/perltest.pl). The script should print the names and values of its environment variables. One of the output lines will show the value of the GATEWAY_INTERFACE environment variable, which should begin with CGI:
GATEWAY_INTERFACE = CGI/1.1
Now copy perltest.pl to the cgi-perl directory and request http://www.snake.net/cgi-perl/perltest.pl so that the script is executed by mod_perl rather than by a standalone Perl process. The output should be similar, but the value of GATEWAY_INTERFACE should begin with cgi-perl, not CGI. This indicates that the CGI environment has been set up by the mod_perl Apache::Registry module. In addition, the output should show a variable MOD_PERL containing your mod_perl version number:
GATEWAY_INTERFACE = cgi-perl/1.1
MOD_PERL = mod_perl/1.24
This exercise with perltest.pl shows how you can run a script either as a standalone CGI program or using mod_perl. It also shows what you need to do if you have a script that needs to know whether it's running under mod_perl. That is, you can use either of the following tests:
if (exists ($ENV{MOD_PERL})) { print "mod_perl yes\n"; }
if ($ENV{GATEWAY_INTERFACE} =~ /^cgi-perl/) { print "mod_perl yes\n"; }
|