Home / What is mod_perl? / | ||||
Log Handler Example | ||||
|
||
Every request phase can be controlled using mod_perl. Here's an
example of a PerlLogHandler
. The PerlLogHandler
is one of the
last phases of the request cycle.
This example sends mail when a request is made to the /private section
of your web space. A more common use of a PerlLogHandler
might be
to track hits on a specific set of URLs, or to write logging data to a
relational database.
file:My/Notify.pm ------------------------ package My::Notify; use strict; use Apache::Constants qw(:common); use Mail::Send; sub handler { my $r = shift; my $email = $r->server->server_admin || return DECLINED; my $mail = Mail::Send->new( To => $email, Subject => "mod_perl Notification", ); my $file = $r->filename; my $fh = $mail->open; $fh->print("File '$file' was accessed"); $fh->close; return DECLINED; # let apache write to the lot } 1; # modules must return true
The httpd.conf setup:
<Location /private> SetHandler perl-script PerlLogHandler My::Notify </Location>« back
|