📄 serverutil.pm
字号:
# # /*# * *********** WARNING **************# * This file generated by ModPerl::WrapXS/0.01# * Any changes made here will be lost# * ***********************************# * 01: lib/ModPerl/Code.pm:708# * 02: lib/ModPerl/WrapXS.pm:624# * 03: lib/ModPerl/WrapXS.pm:1173# * 04: Makefile.PL:423# * 05: Makefile.PL:325# * 06: Makefile.PL:56# */# package Apache2::ServerUtil;use strict;use warnings FATAL => 'all';use Apache2::XSLoader ();our $VERSION = '2.000002';Apache2::XSLoader::load __PACKAGE__;1;__END__=head1 NAMEApache2::ServerUtil - Perl API for Apache server record utils=head1 Synopsis use Apache2::ServerUtil (); $s = Apache2::ServerUtil->server; # push config $s->add_config(['ServerTokens off']); # 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('MODPERL2'); # get PerlChildExitHandler configured handlers @handlers = @{ $s->get_handlers('PerlChildExitHandler') || []}; # server build and version info: $when_built = Apache2::ServerUtil::get_server_built(); $version = Apache2::ServerUtil::get_server_version(); # ServerRoot value $server_root = Apache2::ServerUtil::server_root(); # get 'conf/' dir path (avoid using this function!) my $dir = Apache2::ServerUtil::server_root_relative($r->pool, 'conf'); # set child_exit handlers $r->set_handlers(PerlChildExitHandler => \&handler); # server level PerlOptions flags lookup $s->push_handlers(ChildExit => \&child_exit) if $s->is_perl_option_enabled('ChildExit'); # extend HTTP to support a new method $s->method_register('NEWGET'); # 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;=head1 DescriptionC<Apache2::ServerUtil> provides the L<Apache serverobject|docs::2.0::api::Apache2::ServerRec> utilities API.=head1 Methods APIC<Apache2::ServerUtil> provides the following functions and/or methods:=head2 C<add_config>Dynamically add Apache configuration: $s->add_config($lines);=over 4=item obj: C<$s>( C<L<Apache2::ServerRec object|docs::2.0::api::Apache2::ServerRec>> )=item arg1: C<$lines> ( ARRAY ref )An ARRAY reference containing configuration lines per element, withoutthe new line terminators.=item ret: no return value=item since: 2.0.00=backSee also:C<L<$r-E<gt>add_config|docs::2.0::api::Apache2::RequestUtil/C_add_config_>>For example:Add a configuration section at the server startup (e.g. fromI<startup.pl>): use Apache2::ServerUtil (); my $conf = <<'EOC'; PerlModule Apache2::MyExample <Location /perl> SetHandler perl-script PerlResponseHandler Apache2::MyExample </Location> EOC Apache2::ServerUtil->server->add_config([split /\n/, $conf]);=head2 C<add_version_component>Add a component to the version string $s->add_version_component($component);=over 4=item obj: C<$s>( C<L<Apache2::ServerRec object|docs::2.0::api::Apache2::ServerRec>> )=item arg1: C<$component> ( string )The string component to add=item ret: no return value=item since: 2.0.00=backThis function is usually used by modules to advertise themselves tothe world. It's picked up by such statistics collectors, likenetcraft.com, which accomplish that by connecting to various serversand grabbing the server version response header (C<Server>). Someservers choose to fully or partially conceal that header.This method should be invoked in theC<L<PerlPostConfigHandler|docs::2.0::user::handlers::server/C_PerlPostConfigHandler_>>phase, which will ensure that the Apache core version number willappear first.For example let's add a component I<"Hikers, Inc/0.99999"> to theserver string at the server startup: use Apache2::ServerUtil (); use Apache2::Const -compile => 'OK'; Apache2::ServerUtil->server->push_handlers( PerlPostConfigHandler => \&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; }or of course you could register theC<L<PerlPostConfigHandler|docs::2.0::user::handlers::server/C_PerlPostConfigHandler_>>handler directly in F<httpd.conf>Now when the server starts, you will something like: [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 operationsAlso remember that the C<ServerTokens> directive value controlswhether the component information is displayed or not.=head2 C<server_shutdown_cleanup_register>Register server shutdown cleanup callback: Apache2::ServerUtil::server_shutdown_cleanup_register($sub);=over 4=item arg1: C<$sub> ( CODE ref or SUB name )=item ret: no return value=item since: 2.0.00=backThis function can be used to register a callback to be run once at theserver shutdown (compared toC<L<PerlChildExitHandler|docs::2.0::user::handlers::server/C_PerlChildExitHandler_>>which will execute the callback for each exiting child process).For example in order to arrange the function C<do_my_cleanups()> to berun every time the server shuts down (or restarts), run the followingcode at the server startup: Apache2::ServerUtil::server_shutdown_cleanup_register(\&do_my_cleanups);It's necessary to run this code at the server startup (normallyF<startup.pl>. The function will croak if run after theC<L<PerlPostConfigHandler|docs::2.0::user::handlers::server/C_PerlPostConfigHandler_>>phase.=head2 C<dir_config>C<$s-E<gt>dir_config()> provides an interface for the per-servervariables specified by the C<PerlSetVar> and C<PerlAddVar> directives,and also can be manipulated via theC<L<APR::Table|docs::2.0::api::APR::Table>> methods. $table = $s->dir_config(); $value = $s->dir_config($key); @values = $s->dir_config($key); $s->dir_config($key, $val);=over 4=item obj: C<$s>( C<L<Apache2::ServerRec object|docs::2.0::api::Apache2::ServerRec>> )=item opt arg2: C<$key> ( string )Key string=item opt arg3: C<$val> ( string )Value string=item ret: ...Depends on the passed arguments, see further discussion=item since: 2.0.00=backThe keys are case-insensitive. $t = $s->dir_config();dir_config() called in a scalar context without the C<$key> argumentreturns a I<HASH> reference blessed into the I<APR::Table> class. Thisobject can be manipulated via the I<APR::Table> methods. For availablemethods see I<APR::Table>. @values = $s->dir_config($key);If the C<$key> argument is passed in the list context a list of allmatching values will be returned. This method is ineffective for bigtables, as it does a linear search of the table. Thefore avoid usingthis way of calling dir_config() unless you know that there could bemore than one value for the wanted key and all the values are wanted. $value = $s->dir_config($key);If the C<$key> argument is passed in the scalar context only a singlevalue will be returned. Since the table preserves the insertion order,if there is more than one value for the same key, the oldest valueassosiated with the desired key is returned. Calling in the scalarcontext is also much faster, as it'll stop searching the table as soonas the first match happens. $s->dir_config($key => $val);If the C<$key> and the C<$val> arguments are used, the set() operationwill happen: all existing values associated with the key C<$key> (andthe key itself) will be deleted and C<$value> will be placed instead. $s->dir_config($key => undef);If C<$val> is I<undef> the unset() operation will happen: all existingvalues associated with the key C<$key> (and the key itself) will bedeleted.=head2 C<exists_config_define>Check for a definition from the server startup command line(e.g. C<-DMODPERL2>) $result = Apache2::ServerUtil::exists_config_define($name);=over 4=item arg1: C<$name> ( string )The define string to check for=item ret: C<$result> ( boolean )true if defined, false otherwise=item since: 2.0.00=backFor example: print "this is mp2" if Apache2::ServerUtil::exists_config_define('MODPERL2');=head2 C<get_handlers>Returns a reference to a list of handlers enabled fora given phase. $handlers_list = $s->get_handlers($hook_name);=over 4=item obj: C<$s>( C<L<Apache2::ServerRec object|docs::2.0::api::Apache2::ServerRec>> )=item arg1: C<$hook_name> ( string )a string representing the phase to handle.=item ret: C<$handlers_list> (ref to an ARRAY of CODE refs)a list of references to the handler subroutines=item since: 2.0.00=backSee also:C<L<$r-E<gt>add_config|docs::2.0::api::Apache2::RequestUtil/C_get_handlers_>>For example:A list of handlers configured to run at the I<child_exit> phase: @handlers = @{ $s->get_handlers('PerlChildExitHandler') || []};=head2 C<get_server_built>Get the date and time that the server was built $when_built = Apache2::ServerUtil::get_server_built();=over 4=item ret: C<$when_built> ( string )The server build time string=item since: 2.0.00=back=head2 C<get_server_version>Get the server version string $version = Apache2::ServerUtil::get_server_version();=over 4=item ret: C<$version> ( string )The server version string=item since: 2.0.00=back=head2 C<is_perl_option_enabled>check whether a server level C<PerlOptions> flag is enabled or not. $result = $s->is_perl_option_enabled($flag);=over 4=item obj: C<$s>( C<L<Apache2::ServerRec object|docs::2.0::api::Apache2::ServerRec>> )=item arg1: C<$flag> ( string )=item ret: C<$result> ( boolean )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -