📄 apache2::serverutil.3
字号:
.IX Subsection "restart_count"How many times the server was restarted..PP.Vb 1\& $restart_count = Apache2::ServerUtil::restart_count();.Ve.ie n .IP "ret: ""restart_count"" ( number )" 4.el .IP "ret: \f(CWrestart_count\fR ( number )" 4.IX Item "ret: restart_count ( number )".PD 0.IP "since: 2.0.00" 4.IX Item "since: 2.0.00".PD.PPThe following demonstration should make it clear what values to expectfrom this function. Let's add the following code to \fIstartup.pl\fR, soit's run every time \fIhttpd.conf\fR is parsed:.PP.Vb 5\& use Apache2::ServerUtil ();\& my $cnt = Apache2::ServerUtil::restart_count();\& open my $fh, ">>/tmp/out" or die "$!";\& print $fh "cnt: $cnt\en";\& close $fh;.Ve.PPNow let's run a series of server starts and restarts and look at whatis logged into \fI/tmp/out\fR:.PP.Vb 3\& % httpd \-k start\& cnt: 1\& cnt: 2\& \& % httpd \-k graceful\& cnt: 1\& cnt: 3\& \& % httpd \-k graceful\& cnt: 1\& cnt: 4\& \& % httpd \-k stop\& cnt: 1.Ve.PPRemembering that Apache restarts itself immediately afterstarting, we cansee that the \f(CW\*(C`restart_count\*(C'\fR goes from 1 to 2 during the serverstart. Moreover we can see that every operation forces the parsing of\&\fIhttpd.conf\fR and therefore reinitialization of mod_perl (and runningall the code found in \fIhttpd.conf\fR). This happens even when theserver is shutdown via \f(CW\*(C`httpd \-k stop\*(C'\fR..PPWhat conclusions can be drawn from this demonstration:.IP "\(bu" 4\&\f(CW\*(C`Apache2::ServerUtil::restart_count()\*(C'\fR returns 1 every time some \f(CW\*(C`\-k\*(C'\fRcommand is passed to Apache (or \f(CW\*(C`kill \-USR1\*(C'\fR or some alternativesignal is received)..IP "\(bu" 4At all other times the count will be 2 or higher. So for example ongraceful restart the count will be 3 or higher..PPFor example if you want to run something every time \f(CW\*(C`httpd \-k\*(C'\fR is runyou just need to check whether \f(CW\*(C`restart_count()\*(C'\fR returns 1:.PP.Vb 2\& my $cnt = Apache2::ServerUtil::restart_count();\& do_something() if $cnt == 1;.Ve.PPTo do something only when server restarts (\f(CW\*(C`httpd \-k start\*(C'\fR or\&\f(CW\*(C`httpd \-k graceful)\*(C'\fR, check whether \f(CW\*(C`restart_count()\*(C'\fR is bigger than1:.PP.Vb 2\& my $cnt = Apache2::ServerUtil::restart_count();\& do_something() if $cnt > 1;.Ve.ie n .Sh """server""".el .Sh "\f(CWserver\fP".IX Subsection "server"Get the main server's object.PP.Vb 1\& $main_s = Apache2::ServerUtil\->server();.Ve.ie n .IP "obj: ""Apache2"" (class name)" 4.el .IP "obj: \f(CWApache2\fR (class name)" 4.IX Item "obj: Apache2 (class name)".PD 0.ie n .IP "ret: $main_s\fR ( \f(CW""Apache2::ServerRec object"" )" 4.el .IP "ret: \f(CW$main_s\fR ( \f(CWApache2::ServerRec object\fR )" 4.IX Item "ret: $main_s ( Apache2::ServerRec object )".IP "since: 2.0.00" 4.IX Item "since: 2.0.00".PD.ie n .Sh """server_root""".el .Sh "\f(CWserver_root\fP".IX Subsection "server_root"returns the value set by the top-level \f(CW\*(C`ServerRoot\*(C'\fR directive..PP.Vb 1\& $server_root = Apache2::ServerUtil::server_root();.Ve.ie n .IP "ret: $server_root ( string )" 4.el .IP "ret: \f(CW$server_root\fR ( string )" 4.IX Item "ret: $server_root ( string )".PD 0.IP "since: 2.0.00" 4.IX Item "since: 2.0.00".PD.ie n .Sh """server_root_relative""".el .Sh "\f(CWserver_root_relative\fP".IX Subsection "server_root_relative"Returns the canonical form of the filename made absolute to\&\f(CW\*(C`ServerRoot\*(C'\fR:.PP.Vb 1\& $path = Apache2::ServerUtil::server_root_relative($pool, $fname);.Ve.ie n .IP "arg1: $pool\fR ( \f(CW""APR::Pool object"" )" 4.el .IP "arg1: \f(CW$pool\fR ( \f(CWAPR::Pool object\fR )" 4.IX Item "arg1: $pool ( APR::Pool object )"Make sure that you read the following explanation and understand wellwhich pool object you need to pass before using this function..ie n .IP "opt arg2: $fname ( string )" 4.el .IP "opt arg2: \f(CW$fname\fR ( string )" 4.IX Item "opt arg2: $fname ( string )".PD 0.ie n .IP "ret: $path ( string )" 4.el .IP "ret: \f(CW$path\fR ( string )" 4.IX Item "ret: $path ( string )".PDThe concatenation of \f(CW\*(C`ServerRoot\*(C'\fR and the \f(CW$fname\fR..SpIf \f(CW$fname\fR is not specified, the value of \f(CW\*(C`ServerRoot\*(C'\fR is returnedwith a trailing \f(CW\*(C`/\*(C'\fR. (it's the same as using \f(CW\*(Aq\*(Aq\fR as \f(CW$fname\fR'svalue)..IP "since: 2.0.00" 4.IX Item "since: 2.0.00".PP\&\f(CW$fname\fR is appended to the value of \f(CW\*(C`ServerRoot\*(C'\fR and returned. Forexample:.PP.Vb 1\& my $dir = Apache2::ServerUtil::server_root_relative($r\->pool, \*(Aqlogs\*(Aq);.Ve.PPYou must be extra-careful when using this function. If you aren't surewhat you are doing don't use it..PPIt's much safer to build the path by yourself using use\&\f(CW\*(C`Apache2::ServerUtil::server_root()\*(C'\fR, Forexample:.PP.Vb 2\& use File::Spec::Functions qw(catfile);\& my $path = catfile Apache2::ServerUtil::server_root, qw(t logs);.Ve.PPIn this example, no memory allocation happens on the Apache-side andyou aren't risking to get a memory leak..PPThe problem with \f(CW\*(C`server_root_relative\*(C'\fR is that Apache allocatesmemory to concatenate the path string. The memory is allocated fromthe pool object. If you call this method on the server pool objectit'll allocate the memory from it. If you do that at the serverstartup, it's perfectly right, since you will do that onlyonce. However if you do that from within a request or a connectionhandler, you create a memory leak every time it is called \*(-- as thememory gets allocated from the server pool, it will be freed only whenthe server is shutdown. Therefore if you need to build a relative tothe root server path for the duration of the request, use the requestpool:.PP.Vb 2\& use Apache2::RequestRec ();\& Apache2::ServerUtil::server_root_relative($r\->pool, $fname);.Ve.PPIf you need to have the path for the duration of a connection(e.g. inside a protocol handler), you should use:.PP.Vb 2\& use Apache2::Connection ();\& Apache2::ServerUtil::server_root_relative($c\->pool, $fname);.Ve.PPAnd if you want it for the scope of the server file:.PP.Vb 3\& use Apache2::Process ();\& use Apache2::ServerUtil ();\& Apache2::ServerUtil::server_root_relative($s\->process\->pool, $fname);.Ve.PPMoreover, you could have encountered the opposite problem, where youhave used a short-lived pool object to construct the path, but triedto use the resulting path variable, when that pool has been destructedalready. In order to avoid mysterious segmentation faults, mod_perldoes a wasteful copy of the path string when returning it to you \*(--another reason to avoid using this function..ie n .Sh """set_handlers""".el .Sh "\f(CWset_handlers\fP".IX Subsection "set_handlers"Set a list of handlers to be called for a given phase. Any previouslyset handlers are forgotten..PP.Vb 4\& $ok = $s\->set_handlers($hook_name => \e&handler);\& $ok = $s\->set_handlers($hook_name => [\e&handler, \e&handler2]);\& $ok = $s\->set_handlers($hook_name => []);\& $ok = $s\->set_handlers($hook_name => undef);.Ve.ie n .IP "obj: $s\fR ( \f(CW""Apache2::ServerRec object"" )" 4.el .IP "obj: \f(CW$s\fR ( \f(CWApache2::ServerRec object\fR )" 4.IX Item "obj: $s ( Apache2::ServerRec object )".PD 0.ie n .IP "arg1: $hook_name ( string )" 4.el .IP "arg1: \f(CW$hook_name\fR ( string )" 4.IX Item "arg1: $hook_name ( string )".PDthe phase to set the handlers in.ie n .IP "arg2: $handlers ( \s-1CODE\s0 ref or \s-1SUB\s0 name or an \s-1ARRAY\s0 ref )" 4.el .IP "arg2: \f(CW$handlers\fR ( \s-1CODE\s0 ref or \s-1SUB\s0 name or an \s-1ARRAY\s0 ref )" 4.IX Item "arg2: $handlers ( CODE ref or SUB name or an ARRAY ref )"a reference to a single handler \s-1CODE\s0 reference or just a name of thesubroutine (fully qualified unless defined in the current package)..Spif more than one passed, use a reference to an array of \s-1CODE\s0 refsand/or subroutine names..Spif the argument is \f(CW\*(C`undef\*(C'\fR or \f(CW\*(C`[]\*(C'\fR the list of handlers is reset tozero..ie n .IP "ret: $ok ( boolean )" 4.el .IP "ret: \f(CW$ok\fR ( boolean )" 4.IX Item "ret: $ok ( boolean )"returns a true value on success, otherwise a false value.IP "since: 2.0.00" 4.IX Item "since: 2.0.00".PPSee also:\&\f(CW\*(C`$r\->add_config\*(C'\fR.PPExamples:.PPA single handler:.PP.Vb 1\& $r\->set_handlers(PerlChildExitHandler => \e&handler);.Ve.PPMultiple handlers:.PP.Vb 1\& $r\->set_handlers(PerlFixupHandler => [\*(AqFoo::Bar::handler\*(Aq, \e&handler2]);.Ve.PPAnonymous functions:.PP.Vb 1\& $r\->set_handlers(PerlLogHandler => sub { return Apache2::Const::OK });.Ve.PPReset any previously set handlers:.PP.Vb 1\& $r\->set_handlers(PerlCleanupHandler => []);.Ve.PPor.PP.Vb 1\& $r\->set_handlers(PerlCleanupHandler => undef);.Ve.SH "Unsupported API".IX Header "Unsupported API"\&\f(CW\*(C`Apache2::ServerUtil\*(C'\fR also provides auto-generated Perl interface fora few other methods which aren't tested at the moment and thereforetheir \s-1API\s0 is a subject to change. These methods will be finalizedlater as a need arises. If you want to rely on any of the followingmethods please contact the the mod_perl development mailinglist so we can help each other take the steps necessaryto shift the method to an officially supported \s-1API\s0..ie n .Sh """error_log2stderr""".el .Sh "\f(CWerror_log2stderr\fP".IX Subsection "error_log2stderr"Start sending \s-1STDERR\s0 to the error_log file.PP.Vb 1\& $s\->error_log2stderr();.Ve.ie n .IP "obj: $s\fR ( \f(CW""Apache2::ServerRec object"" )" 4.el .IP "obj: \f(CW$s\fR ( \f(CWApache2::ServerRec object\fR )" 4.IX Item "obj: $s ( Apache2::ServerRec object )"The current server.IP "ret: no return value" 4.IX Item "ret: no return value".PD 0.IP "since: 2.0.00" 4.IX Item "since: 2.0.00".PD.PPThis method may prove useful if you want to start redirecting \s-1STDERR\s0to the error_log file before Apache does that on the startup..SH "See Also".IX Header "See Also"mod_perl 2.0 documentation..SH "Copyright".IX Header "Copyright"mod_perl 2.0 and its core modules are copyrighted underThe Apache Software License, Version 2.0..SH "Authors".IX Header "Authors"The mod_perl development team and numerouscontributors.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -