我想創建一個自定義的Apache2日誌處理程序,那就是在Apache的網站上找到的模板是:如何確定PerlLogHandler性能影響?
#file:MyApache2/LogPerUser.pm
#---------------------------
package MyApache2::LogPerUser;
use strict;
use warnings;
use Apache2::RequestRec();
use Apache2::Connection();
use Fcntl qw(:flock);
use File::Spec::Functions qw(catfile);
use Apache2::Const -compile => qw(OK DECLINED);
sub handler {
my $r = shift;
my ($username) = $r->uri =~ m|^/~([^/]+)|;
return Apache2::Const::DECLINED unless defined $username;
my $entry = sprintf qq(%s [%s] "%s" %d %d\n),
$r->connection->remote_ip, scalar(localtime),
$r->uri, $r->status, $r->bytes_sent;
my $log_path = catfile Apache2::ServerUtil::server_root,
"logs", "$username.log";
open my $fh, ">>$log_path" or die "can't open $log_path: $!";
flock $fh, LOCK_EX;
print $fh $entry;
close $fh;
return Apache2::Const::OK;
}
1;
什麼是成羣的性能開銷?這個日誌過程是並行完成的,還是與HTTP請求串行完成的?同時,性能並不重要,但我不希望用戶等待另一秒鐘來添加這樣的內容。