#!/usr/bin/perl BEGIN { my $path = $ENV{'DOCUMENT_ROOT'} || $0; while ($path =~ s/(.*)(\/.*)/$1/i) { require "$path/init.pl" if (-e "$path/init.pl"); } require "/home/betsyann/cm5/startup.pl" if (-e "/home/betsyann/cm5/startup.pl"); } use strict; use CGI::Fast; use Time::HiRes; use XML::Simple; use vars qw($server $reason); &warmup(); while (my $q = CGI::Fast->new()) { # init $t0, $bench_page and $bench_link my $t0 = Time::HiRes::gettimeofday(); my $bench_page = $server->location_from_query($q); my $bench_link = $q->url(-full => 1, -path => 1, -query => 1); # respond to request my $r = $server->respond($q); # insert benchmark record my $t1 = Time::HiRes::gettimeofday(); my $bench_time = $t1 - $t0; $server->dbh()->do( qq{ INSERT DELAYED INTO s__benchmark SET type = 'SINGLETON', page = ?, bench_time = ?, bench_hits = 1, bench_date = NOW(), created_on = NOW(), changed_on = NOW() }, {}, $bench_page, $bench_time, $bench_link ); # print out the response print $r->headers()->as_string() . "\n" . $r->content(); # check script modified if (-M $ENV{SCRIPT_FILENAME} < 0) { $server->exit_requested(1); $reason = "script modified"; } # exit requested last if ($server->exit_requested()); } $reason = "end of loop"; &cleanup(); exit(0); # initialization sub warmup { my $xs = XML::Simple->new( 'cache' => 'memshare', 'forcearray' => 1, 'xmldecl' => '', 'KeyAttr' => { 'redirect' => '+id', 'gallery' => '+name', 'notification' => '+id', }, ); $server = Acx::Page::Server->new('xs' => $xs); $reason = ''; $SIG{USR1} = \&sig_handler; $SIG{TERM} = \&sig_handler; $SIG{PIPE} = 'IGNORE'; } sub cleanup { $server->stop(); return 1; } sub sig_handler { my $sig_name = shift @_; &cleanup() && exit(0) unless ($server->handling_request()); $server->exit_requested(1); } 1;