.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.40) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "libapache2-mod-perl2-2.0.11::docs::api::Apache2::ServerUtil 3pm" .TH libapache2-mod-perl2-2.0.11::docs::api::Apache2::ServerUtil 3pm "2021-05-21" "perl v5.32.1" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Apache2::ServerUtil \- Perl API for Apache server record utils .SH "Synopsis" .IX Header "Synopsis" .Vb 2 \& use Apache2::ServerUtil (); \& $s = Apache2::ServerUtil\->server; \& \& # push config \& $s\->add_config([\*(AqServerTokens off\*(Aq]); \& \& # add components to the Server signature \& $s\->add_version_component("MyModule/1.234"); \& \& # access PerlSetVar/PerlAddVar values \& my $srv_cfg = $s\->dir_config; \& \& # check command line defines \& print "this is mp2" \& if Apache2::ServerUtil::exists_config_define(\*(AqMODPERL2\*(Aq); \& \& # get PerlChildExitHandler configured handlers \& @handlers = @{ $s\->get_handlers(\*(AqPerlChildExitHandler\*(Aq) || []}; \& \& # server build and version info: \& $when_built = Apache2::ServerUtil::get_server_built(); \& $description = Apache2::ServerUtil::get_server_description(); \& $version = Apache2::ServerUtil::get_server_version(); \& $banner = Apache2::ServerUtil::get_server_banner(); \& \& # ServerRoot value \& $server_root = Apache2::ServerUtil::server_root(); \& \& # get \*(Aqconf/\*(Aq dir path (avoid using this function!) \& my $dir = Apache2::ServerUtil::server_root_relative($r\->pool, \*(Aqconf\*(Aq); \& \& # set child_exit handlers \& $r\->set_handlers(PerlChildExitHandler => \e&handler); \& \& # server level PerlOptions flags lookup \& $s\->push_handlers(ChildExit => \e&child_exit) \& if $s\->is_perl_option_enabled(\*(AqChildExit\*(Aq); \& \& # extend HTTP to support a new method \& $s\->method_register(\*(AqNEWGET\*(Aq); \& \& # register server shutdown callback \& Apache2::ServerUtil::server_shutdown_register_cleanup(sub { Apache2::Const::OK }); \& \& # do something only when the server restarts \& my $cnt = Apache2::ServerUtil::restart_count(); \& do_something_once() if $cnt > 1; \& \& # get the resolved ids from Group and User entries \& my $user_id = Apache2::ServerUtil\->user_id; \& my $group_id = Apache2::ServerUtil\->group_id; .Ve .SH "Description" .IX Header "Description" \&\f(CW\*(C`Apache2::ServerUtil\*(C'\fR provides the Apache server object utilities \s-1API.\s0 .SH "Methods API" .IX Header "Methods API" \&\f(CW\*(C`Apache2::ServerUtil\*(C'\fR provides the following functions and/or methods: .ie n .SS """add_config""" .el .SS "\f(CWadd_config\fP" .IX Subsection "add_config" Dynamically add Apache configuration: .PP .Vb 1 \& $s\->add_config($lines); .Ve .ie n .IP "obj: $s ( ""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: $lines ( \s-1ARRAY\s0 ref )" 4 .el .IP "arg1: \f(CW$lines\fR ( \s-1ARRAY\s0 ref )" 4 .IX Item "arg1: $lines ( ARRAY ref )" .PD An \s-1ARRAY\s0 reference containing configuration lines per element, without the new line terminators. .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 .PP See also: \&\f(CW\*(C`$r\->add_config\*(C'\fR .PP For example: .PP Add a configuration section at the server startup (e.g. from \&\fIstartup.pl\fR): .PP .Vb 9 \& use Apache2::ServerUtil (); \& my $conf = <<\*(AqEOC\*(Aq; \& PerlModule Apache2::MyExample \& \& SetHandler perl\-script \& PerlResponseHandler Apache2::MyExample \& \& EOC \& Apache2::ServerUtil\->server\->add_config([split /\en/, $conf]); .Ve .ie n .SS """add_version_component""" .el .SS "\f(CWadd_version_component\fP" .IX Subsection "add_version_component" Add a component to the version string .PP .Vb 1 \& $s\->add_version_component($component); .Ve .ie n .IP "obj: $s ( ""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: $component ( string )" 4 .el .IP "arg1: \f(CW$component\fR ( string )" 4 .IX Item "arg1: $component ( string )" .PD The string component to add .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 .PP This function is usually used by modules to advertise themselves to the world. It's picked up by such statistics collectors, like netcraft.com, which accomplish that by connecting to various servers and grabbing the server version response header (\f(CW\*(C`Server\*(C'\fR). Some servers choose to fully or partially conceal that header. .PP This method should be invoked in the \&\f(CW\*(C`PerlPostConfigHandler\*(C'\fR phase, which will ensure that the Apache core version number will appear first. .PP For example let's add a component \fI\*(L"Hikers, Inc/0.99999\*(R"\fR to the server string at the server startup: .PP .Vb 2 \& use Apache2::ServerUtil (); \& use Apache2::Const \-compile => \*(AqOK\*(Aq; \& \& Apache2::ServerUtil\->server\->push_handlers( \& PerlPostConfigHandler => \e&add_my_version); \& \& sub add_my_version { \& my ($conf_pool, $log_pool, $temp_pool, $s) = @_; \& $s\->add_version_component("Hikers, Inc/0.99999"); \& return Apache2::Const::OK; \& } .Ve .PP or of course you could register the \&\f(CW\*(C`PerlPostConfigHandler\*(C'\fR handler directly in \fIhttpd.conf\fR .PP Now when the server starts, you will something like: .PP .Vb 3 \& [Thu Jul 15 12:15:28 2004] [notice] Apache/2.0.51\-dev (Unix) \& mod_perl/1.99_15\-dev Perl/v5.8.5 Hikers, Inc/0.99999 \& configured \-\- resuming normal operations .Ve .PP Also remember that the \f(CW\*(C`ServerTokens\*(C'\fR directive value controls whether the component information is displayed or not. .ie n .SS """dir_config""" .el .SS "\f(CWdir_config\fP" .IX Subsection "dir_config" \&\f(CW\*(C`$s\->dir_config()\*(C'\fR provides an interface for the per-server variables specified by the \f(CW\*(C`PerlSetVar\*(C'\fR and \f(CW\*(C`PerlAddVar\*(C'\fR directives, and also can be manipulated via the \&\f(CW\*(C`APR::Table\*(C'\fR methods. .PP .Vb 4 \& $table = $s\->dir_config(); \& $value = $s\->dir_config($key); \& @values = $s\->dir_config\->get($key); \& $s\->dir_config($key, $val); .Ve .ie n .IP "obj: $s ( ""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 "opt arg2: $key ( string )" 4 .el .IP "opt arg2: \f(CW$key\fR ( string )" 4 .IX Item "opt arg2: $key ( string )" .PD Key string .ie n .IP "opt arg3: $val ( string )" 4 .el .IP "opt arg3: \f(CW$val\fR ( string )" 4 .IX Item "opt arg3: $val ( string )" Value string .IP "ret: ..." 4 .IX Item "ret: ..." Depends on the passed arguments, see further discussion .IP "since: 2.0.00" 4 .IX Item "since: 2.0.00" .PP The keys are case-insensitive. .PP .Vb 1 \& $t = $s\->dir_config(); .Ve .PP \&\fBdir_config()\fR called in a scalar context without the \f(CW$key\fR argument returns a \fI\s-1HASH\s0\fR reference blessed into the \fIAPR::Table\fR class. This object can be manipulated via the \fIAPR::Table\fR methods. For available methods see \fIAPR::Table\fR. .PP .Vb 1 \& @values = $s\->dir_config\->get($key); .Ve .PP To receive a list of values you must use \f(CW\*(C`get()\*(C'\fR method from the \&\f(CW\*(C`APR::Table\*(C'\fR class. .PP .Vb 1 \& $value = $s\->dir_config($key); .Ve .PP If the \f(CW$key\fR argument is passed in the scalar context only a single value will be returned. Since the table preserves the insertion order, if there is more than one value for the same key, the oldest value associated with the desired key is returned. Calling in the scalar context is also much faster, as it'll stop searching the table as soon as the first match happens. .PP .Vb 1 \& $s\->dir_config($key => $val); .Ve .PP If the \f(CW$key\fR and the \f(CW$val\fR arguments are used, the \fBset()\fR operation will happen: all existing values associated with the key \f(CW$key\fR (and the key itself) will be deleted and \f(CW$value\fR will be placed instead. .PP .Vb 1 \& $s\->dir_config($key => undef); .Ve .PP If \f(CW$val\fR is \fIundef\fR the \fBunset()\fR operation will happen: all existing values associated with the key \f(CW$key\fR (and the key itself) will be deleted. .ie n .SS """exists_config_define""" .el .SS "\f(CWexists_config_define\fP" .IX Subsection "exists_config_define" Check for a definition from the server startup command line (e.g. \f(CW\*(C`\-DMODPERL2\*(C'\fR) .PP .Vb 1 \& $result = Apache2::ServerUtil::exists_config_define($name); .Ve .ie n .IP "arg1: $name ( string )" 4 .el .IP "arg1: \f(CW$name\fR ( string )" 4 .IX Item "arg1: $name ( string )" The define string to check for .ie n .IP "ret: $result ( boolean )" 4 .el .IP "ret: \f(CW$result\fR ( boolean )" 4 .IX Item "ret: $result ( boolean )" true if defined, false otherwise .IP "since: 2.0.00" 4 .IX Item "since: 2.0.00" .PP For example: .PP .Vb 2 \& print "this is mp2" \& if Apache2::ServerUtil::exists_config_define(\*(AqMODPERL2\*(Aq); .Ve .ie n .SS """get_handlers""" .el .SS "\f(CWget_handlers\fP" .IX Subsection "get_handlers" Returns a reference to a list of handlers enabled for a given phase. .PP .Vb 1 \& $handlers_list = $s\->get_handlers($hook_name); .Ve .ie n .IP "obj: $s ( ""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 )" .PD a string representing the phase to handle. .ie n .IP "ret: $handlers_list (ref to an \s-1ARRAY\s0 of \s-1CODE\s0 refs)" 4 .el .IP "ret: \f(CW$handlers_list\fR (ref to an \s-1ARRAY\s0 of \s-1CODE\s0 refs)" 4 .IX Item "ret: $handlers_list (ref to an ARRAY of CODE refs)" a list of references to the handler subroutines .IP "since: 2.0.00" 4 .IX Item "since: 2.0.00" .PP See also: \&\f(CW\*(C`$r\->add_config\*(C'\fR .PP For example: .PP A list of handlers configured to run at the \fIchild_exit\fR phase: .PP .Vb 1 \& @handlers = @{ $s\->get_handlers(\*(AqPerlChildExitHandler\*(Aq) || []}; .Ve .ie n .SS """get_server_built""" .el .SS "\f(CWget_server_built\fP" .IX Subsection "get_server_built" Get the date and time that the server was built .PP .Vb 1 \& $when_built = Apache2::ServerUtil::get_server_built(); .Ve .ie n .IP "ret: $when_built ( string )" 4 .el .IP "ret: \f(CW$when_built\fR ( string )" 4 .IX Item "ret: $when_built ( string )" The server build time string .IP "since: 2.0.00" 4 .IX Item "since: 2.0.00" .ie n .SS """get_server_version""" .el .SS "\f(CWget_server_version\fP" .IX Subsection "get_server_version" Get the server version string .PP .Vb 1 \& $version = Apache2::ServerUtil::get_server_version(); .Ve .ie n .IP "ret: $version ( string )" 4 .el .IP "ret: \f(CW$version\fR ( string )" 4 .IX Item "ret: $version ( string )" The server version string .IP "since: 2.0.00" 4 .IX Item "since: 2.0.00" .ie n .SS """get_server_banner""" .el .SS "\f(CWget_server_banner\fP" .IX Subsection "get_server_banner" Get the server banner .PP .Vb 1 \& $banner = Apache2::ServerUtil::get_server_banner(); .Ve .ie n .IP "ret: $banner ( string )" 4 .el .IP "ret: \f(CW$banner\fR ( string )" 4 .IX Item "ret: $banner ( string )" The server banner .IP "since: 2.0.4" 4 .IX Item "since: 2.0.4" .ie n .SS """get_server_description""" .el .SS "\f(CWget_server_description\fP" .IX Subsection "get_server_description" Get the server description .PP .Vb 1 \& $description = Apache2::ServerUtil::get_server_description(); .Ve .ie n .IP "ret: $description ( string )" 4 .el .IP "ret: \f(CW$description\fR ( string )" 4 .IX Item "ret: $description ( string )" The server description .IP "since: 2.0.4" 4 .IX Item "since: 2.0.4" .ie n .SS """group_id""" .el .SS "\f(CWgroup_id\fP" .IX Subsection "group_id" Get the group id corresponding to the \f(CW\*(C`Group\*(C'\fR directive in \&\fIhttpd.conf\fR: .PP .Vb 1 \& $gid = Apache2::ServerUtil\->group_id; .Ve .ie n .IP "obj: ""Apache2::ServerUtil"" (class name)" 4 .el .IP "obj: \f(CWApache2::ServerUtil\fR (class name)" 4 .IX Item "obj: Apache2::ServerUtil (class name)" .PD 0 .ie n .IP "ret: $gid ( integer )" 4 .el .IP "ret: \f(CW$gid\fR ( integer )" 4 .IX Item "ret: $gid ( integer )" .PD On Unix platforms returns the gid corresponding to the value used in the \f(CW\*(C`Group\*(C'\fR directive in \fIhttpd.conf\fR. On other platforms returns 0. .IP "since: 2.0.03" 4 .IX Item "since: 2.0.03" .ie n .SS """is_perl_option_enabled""" .el .SS "\f(CWis_perl_option_enabled\fP" .IX Subsection "is_perl_option_enabled" check whether a server level \f(CW\*(C`PerlOptions\*(C'\fR flag is enabled or not. .PP .Vb 1 \& $result = $s\->is_perl_option_enabled($flag); .Ve .ie n .IP "obj: $s ( ""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: $flag ( string )" 4 .el .IP "arg1: \f(CW$flag\fR ( string )" 4 .IX Item "arg1: $flag ( string )" .ie n .IP "ret: $result ( boolean )" 4 .el .IP "ret: \f(CW$result\fR ( boolean )" 4 .IX Item "ret: $result ( boolean )" .IP "since: 2.0.00" 4 .IX Item "since: 2.0.00" .PD .PP For example to check whether the \f(CW\*(C`ChildExit\*(C'\fR hook is enabled (which can be disabled with \f(CW\*(C`PerlOptions \-ChildExit\*(C'\fR) and configure some handlers to run if enabled: .PP .Vb 2 \& $s\->push_handlers(ChildExit => \e&child_exit) \& if $s\->is_perl_option_enabled(\*(AqChildExit\*(Aq); .Ve .PP See also: PerlOptions and the equivalent function for directory level PerlOptions flags. .ie n .SS """method_register""" .el .SS "\f(CWmethod_register\fP" .IX Subsection "method_register" Register a new request method, and return the offset that will be associated with that method. .PP .Vb 1 \& $offset = $s\->method_register($methname); .Ve .ie n .IP "obj: $s ( ""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: $methname ( string )" 4 .el .IP "arg1: \f(CW$methname\fR ( string )" 4 .IX Item "arg1: $methname ( string )" .PD The name of the new method to register (in addition to the already supported \f(CW\*(C`GET\*(C'\fR, \f(CW\*(C`HEAD\*(C'\fR, etc.) .ie n .IP "ret: $offset ( integer )" 4 .el .IP "ret: \f(CW$offset\fR ( integer )" 4 .IX Item "ret: $offset ( integer )" An int value representing an offset into a bitmask. You can probably ignore it. .IP "since: 2.0.00" 4 .IX Item "since: 2.0.00" .PP This method allows you to extend the \s-1HTTP\s0 protocol to support new methods, which fit the \s-1HTTP\s0 paradigm. Of course you will need to write a client that understands that protocol extension. For a good example, refer to the \f(CW\*(C`MyApache2::SendEmail\*(C'\fR example presented in \&\f(CW\*(C`the PerlHeaderParserHandler section\*(C'\fR, which demonstrates how a new method \f(CW\*(C`EMAIL\*(C'\fR is registered and used. .ie n .SS """push_handlers""" .el .SS "\f(CWpush_handlers\fP" .IX Subsection "push_handlers" Add one or more handlers to a list of handlers to be called for a given phase. .PP .Vb 2 \& $ok = $s\->push_handlers($hook_name => \e&handler); \& $ok = $s\->push_handlers($hook_name => [\e&handler, \e&handler2]); .Ve .ie n .IP "obj: $s ( ""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 )" .PD the phase to add the handlers to .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 single handler \s-1CODE\s0 reference or just a name of the subroutine (fully qualified unless defined in the current package). .Sp if more than one passed, use a reference to an array of \s-1CODE\s0 refs and/or subroutine names. .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" .PP See also: \&\f(CW\*(C`$r\->add_config\*(C'\fR .PP Examples: .PP A single handler: .PP .Vb 1 \& $s\->push_handlers(PerlChildExitHandler => \e&handler); .Ve .PP Multiple handlers: .PP .Vb 1 \& $s\->push_handlers(PerlChildExitHandler => [\*(AqFoo::Bar::handler\*(Aq, \e&handler2]); .Ve .PP Anonymous functions: .PP .Vb 1 \& $s\->push_handlers(PerlLogHandler => sub { return Apache2::Const::OK }); .Ve .ie n .SS """restart_count""" .el .SS "\f(CWrestart_count\fP" .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 .PP The following demonstration should make it clear what values to expect from this function. Let's add the following code to \fIstartup.pl\fR, so it'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 .PP Now let's run a series of server starts and restarts and look at what is 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 .PP Remembering that Apache restarts itself immediately after starting, we can see that the \f(CW\*(C`restart_count\*(C'\fR goes from 1 to 2 during the server start. Moreover we can see that every operation forces the parsing of \&\fIhttpd.conf\fR and therefore reinitialization of mod_perl (and running all the code found in \fIhttpd.conf\fR). This happens even when the server is shutdown via \f(CW\*(C`httpd \-k stop\*(C'\fR. .PP What 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'\fR command is passed to Apache (or \f(CW\*(C`kill \-USR1\*(C'\fR or some alternative signal is received). .IP "\(bu" 4 At all other times the count will be 2 or higher. So for example on graceful restart the count will be 3 or higher. .PP For example if you want to run something every time \f(CW\*(C`httpd \-k\*(C'\fR is run you 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 .PP To 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 than 1: .PP .Vb 2 \& my $cnt = Apache2::ServerUtil::restart_count(); \& do_something() if $cnt > 1; .Ve .ie n .SS """server""" .el .SS "\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::ServerUtil"" (class name)" 4 .el .IP "obj: \f(CWApache2::ServerUtil\fR (class name)" 4 .IX Item "obj: Apache2::ServerUtil (class name)" .PD 0 .ie n .IP "ret: $main_s ( ""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 .SS """server_root""" .el .SS "\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 .SS """server_root_relative""" .el .SS "\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 ( ""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 well which 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 )" .PD The concatenation of \f(CW\*(C`ServerRoot\*(C'\fR and the \f(CW$fname\fR. .Sp If \f(CW$fname\fR is not specified, the value of \f(CW\*(C`ServerRoot\*(C'\fR is returned with a trailing \f(CW\*(C`/\*(C'\fR. (it's the same as using \f(CW\*(Aq\*(Aq\fR as \f(CW$fname\fR's value). .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. For example: .PP .Vb 1 \& my $dir = Apache2::ServerUtil::server_root_relative($r\->pool, \*(Aqlogs\*(Aq); .Ve .PP You must be extra-careful when using this function. If you aren't sure what you are doing don't use it. .PP It's much safer to build the path by yourself using use \&\f(CW\*(C`Apache2::ServerUtil::server_root()\*(C'\fR, For example: .PP .Vb 2 \& use File::Spec::Functions qw(catfile); \& my $path = catfile Apache2::ServerUtil::server_root, qw(t logs); .Ve .PP In this example, no memory allocation happens on the Apache-side and you aren't risking to get a memory leak. .PP The problem with \f(CW\*(C`server_root_relative\*(C'\fR is that Apache allocates memory to concatenate the path string. The memory is allocated from the pool object. If you call this method on the server pool object it'll allocate the memory from it. If you do that at the server startup, it's perfectly right, since you will do that only once. However if you do that from within a request or a connection handler, you create a memory leak every time it is called \*(-- as the memory gets allocated from the server pool, it will be freed only when the server is shutdown. Therefore if you need to build a relative to the root server path for the duration of the request, use the request pool: .PP .Vb 2 \& use Apache2::RequestRec (); \& Apache2::ServerUtil::server_root_relative($r\->pool, $fname); .Ve .PP If 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 .PP And 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 .PP Moreover, you could have encountered the opposite problem, where you have used a short-lived pool object to construct the path, but tried to use the resulting path variable, when that pool has been destructed already. In order to avoid mysterious segmentation faults, mod_perl does a wasteful copy of the path string when returning it to you \*(-- another reason to avoid using this function. .ie n .SS """server_shutdown_cleanup_register""" .el .SS "\f(CWserver_shutdown_cleanup_register\fP" .IX Subsection "server_shutdown_cleanup_register" Register server shutdown cleanup callback: .PP .Vb 1 \& Apache2::ServerUtil::server_shutdown_cleanup_register($sub); .Ve .ie n .IP "arg1: $sub ( \s-1CODE\s0 ref or \s-1SUB\s0 name )" 4 .el .IP "arg1: \f(CW$sub\fR ( \s-1CODE\s0 ref or \s-1SUB\s0 name )" 4 .IX Item "arg1: $sub ( CODE ref or SUB name )" .PD 0 .IP "ret: no return value" 4 .IX Item "ret: no return value" .IP "since: 2.0.00" 4 .IX Item "since: 2.0.00" .PD .PP This function can be used to register a callback to be run once at the server shutdown (compared to \&\f(CW\*(C`PerlChildExitHandler\*(C'\fR which will execute the callback for each exiting child process). .PP For example in order to arrange the function \f(CW\*(C`do_my_cleanups()\*(C'\fR to be run every time the server shuts down (or restarts), run the following code at the server startup: .PP .Vb 1 \& Apache2::ServerUtil::server_shutdown_cleanup_register(\e&do_my_cleanups); .Ve .PP It's necessary to run this code at the server startup (normally \&\fIstartup.pl\fR). The function will croak if run after the \&\f(CW\*(C`PerlPostConfigHandler\*(C'\fR phase. .PP Values returned from cleanup functions are ignored. If a cleanup dies the exception is stringified and passed to \f(CW\*(C`warn()\*(C'\fR. Usually, this results in printing it to the \fIerror_log\fR. .ie n .SS """set_handlers""" .el .SS "\f(CWset_handlers\fP" .IX Subsection "set_handlers" Set a list of handlers to be called for a given phase. Any previously set 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 ( ""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 )" .PD the 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 the subroutine (fully qualified unless defined in the current package). .Sp if more than one passed, use a reference to an array of \s-1CODE\s0 refs and/or subroutine names. .Sp if the argument is \f(CW\*(C`undef\*(C'\fR or \f(CW\*(C`[]\*(C'\fR the list of handlers is reset to zero. .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" .PP See also: \&\f(CW\*(C`$r\->add_config\*(C'\fR .PP Examples: .PP A single handler: .PP .Vb 1 \& $r\->set_handlers(PerlChildExitHandler => \e&handler); .Ve .PP Multiple handlers: .PP .Vb 1 \& $r\->set_handlers(PerlFixupHandler => [\*(AqFoo::Bar::handler\*(Aq, \e&handler2]); .Ve .PP Anonymous functions: .PP .Vb 1 \& $r\->set_handlers(PerlLogHandler => sub { return Apache2::Const::OK }); .Ve .PP Reset any previously set handlers: .PP .Vb 1 \& $r\->set_handlers(PerlCleanupHandler => []); .Ve .PP or .PP .Vb 1 \& $r\->set_handlers(PerlCleanupHandler => undef); .Ve .ie n .SS """user_id""" .el .SS "\f(CWuser_id\fP" .IX Subsection "user_id" Get the user id corresponding to the \f(CW\*(C`User\*(C'\fR directive in \&\fIhttpd.conf\fR: .PP .Vb 1 \& $uid = Apache2::ServerUtil\->user_id; .Ve .ie n .IP "obj: ""Apache2::ServerUtil"" (class name)" 4 .el .IP "obj: \f(CWApache2::ServerUtil\fR (class name)" 4 .IX Item "obj: Apache2::ServerUtil (class name)" .PD 0 .ie n .IP "ret: $uid ( integer )" 4 .el .IP "ret: \f(CW$uid\fR ( integer )" 4 .IX Item "ret: $uid ( integer )" .PD On Unix platforms returns the uid corresponding to the value used in the \f(CW\*(C`User\*(C'\fR directive in \fIhttpd.conf\fR. On other platforms returns 0. .IP "since: 2.0.03" 4 .IX Item "since: 2.0.03" .SH "Unsupported API" .IX Header "Unsupported API" \&\f(CW\*(C`Apache2::ServerUtil\*(C'\fR also provides auto-generated Perl interface for a few other methods which aren't tested at the moment and therefore their \s-1API\s0 is a subject to change. These methods will be finalized later as a need arises. If you want to rely on any of the following methods please contact the the mod_perl development mailing list so we can help each other take the steps necessary to shift the method to an officially supported \s-1API.\s0 .ie n .SS """error_log2stderr""" .el .SS "\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 ( ""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 .PP This method may prove useful if you want to start redirecting \s-1STDERR\s0 to 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 under The Apache Software License, Version 2.0. .SH "Authors" .IX Header "Authors" The mod_perl development team and numerous contributors.