in reply to mod_perl2 hooks

Hi,

To get example for all handlers, have a look at mod_perl2 HTTP Handlers.

This is a code thats there in "practical mod_perl" itself, which explains few most useful handlers. (works with mod_perl 1.x or with Apache2::compat ).

Apache conf (httpd.conf)

PerlModule Book::StartupLog PerlOpenLogsHandler Book::StartupLog::open_logs PerlPostConfigHandler Book::StartupLog::post_config PerlChildInitHandler Book::StartupLog::child_init PerlChildExitHandler Book::StartupLog::child_exit

The Perl code

package Book::StartupLog; use strict; use warnings; use Apache::Log ( ); use Apache::ServerUtil ( ); use File::Spec::Functions; use Apache::Const -compile => 'OK'; my $log_file = catfile "logs", "startup_log"; my $log_fh; sub open_logs { my($conf_pool, $log_pool, $temp_pool, $s) = @_; my $log_path = Apache::server_root_relative($conf_pool, $log_file) +; $s->warn("opening the log file: $log_path"); open $log_fh, ">>$log_path" or die "can't open $log_path: $!"; my $oldfh = select($log_fh); $| = 1; select($oldfh); say("process $$ is born to reproduce"); return Apache::OK; } sub post_config { my($conf_pool, $log_pool, $temp_pool, $s) = @_; say("configuration is completed"); return Apache::OK; } sub child_exit { my($child_pool, $s) = @_; say("process $$ now exits"); return Apache::OK; } sub child_init { my($child_pool, $s) = @_; say("process $$ is born to serve"); return Apache::OK; } sub say { my($caller) = (caller(1))[3] =~ /([^:]+)$/; if (defined $log_fh) { printf $log_fh "[%s] - %-11s: %s\n", scalar(localtime), $caller, $_[0]; } else { # when the log file is not open warn __PACKAGE__ . " says: $_[0]\n"; } } END { say("process $$ is shutdown\n"); } 1;
Hope this helps.

Cheers !

--VC



There are three sides to any argument.....
your side, my side and the right side.