2021年01月22日 13:08
mod_perl brings together two of the most powerful and mature technologies available to the web professional today.
mp2 is mod_perl for the 2.x.x branch of the Apache HTTPD Server.
mp1 is mod_perl for the 1.3 branch of the Apache HTTPD Server.
mp2 is fully compatible with httpd 2.0.x , and supports most of the 2.2.x feature set.
mod_perl's future plans are to keep on supporting httpd as it evolves - that has always been the goal, and will always be so.
Simply install mod_perl and you have the full power of the Apache Web Server at your fingertips:
The standard Apache::Registry module can provide 100x speedups for your existing CGI scripts and reduce the load on your server at the same time. A few changes to the web server's config is all that is required to run your existing CGI scripts at lightning speed. more »
Existing CGI scripts will run much faster under mod_perl. And converting existing CGI scripts to run under mod_perl is easy.
For example, here's an existing CGI script called hello.cgi
.
file:hello.cgi
--------------
#!/usr/local/bin/perl -w
use strict;
use CGI;
my $q = CGI->new;
print $q->header,
$q->start_html,
$q->h1('Hello World!'),
$q->end_html;
This script can now be run as-is underApache::Registry
by using the following configuration inhttpd.conf
:
<Files hello.cgi>
SetHandler perl-script
PerlHandler Apache::Registry
Options ExecCGI
</Files>
That's basically it. Your scripts do need to be well coded, but there's even the Apache::PerlRun
module to help with those "less clean" programs.
So how much faster do scripts run underApache::Registry
? Obviously, it depends on the script, but thehello.cgi
script above ran at 7.3 requests per second as a CGI script and 243.0 requests per second withApache::Registry
.
For more information on running CGI scripts under mod_perl please see the CGI to mod_perl Porting section of The Guide.
Handlers are simply perl subroutines called by the server at various stages of the HTTP request cycle. A content handler is a subroutine that is called by the response phase. Handlers, are typically created as a perl modules, separate files store in a library, and accessible via perl's @INC
array.
For example, here's an example that returns a greeting and the current local time.
#file:My/Greeting.pm
#-------------------
package My::Greeting;
use strict;
use Apache::Constants qw(OK);
sub handler {
my $r = shift;
my $now = scalar localtime;
my $server_name = $r->server->server_hostname;
$r->send_http_header('text/plain');
print <<EOT;
Thanks for visiting $server_name.
The local time is $now.
EOT
return OK;
}
1; # modules must return true
Save the above as a file file in your perl library (e.g.My/Greeting.pm
). Now, to return the above greeting when the URL/hello
is visited on your server:
<Location /hello>
SetHandler perl-script
PerlHandler My::Greeting
</Location>
For a more in-depth explanation of creating mod_perl handlers, and mod_perl in general, see the mod_perl Guide.