++ed by:

2 PAUSE users

Randy J Ray


Apache::RPC::Server - A subclass of RPC::XML::Server class tuned for mod_perl


    # In httpd.conf:
    PerlSetVar RpcMethodDir /var/www/rpc:/usr/lib/perl5/RPC-shared
    PerlChildInitHandler Apache::RPC::Server->init_handler
    <Location /RPC>
        SetHandler perl-script
        PerlHandler Apache::RPC::Server
    </Location /RPC-limited>
        SetHandler perl-script
        PerlHandler Apache::RPC::Server
        PerlSetVar RPCOptPrefix RpcLimit
        PerlSetVar RpcLimitRpcServer Limited
        PerlSetVar RpcLimitRpcMethodDir /usr/lib/perl5/RPC-shared

    # In the start-up Perl file:
    use Apache::RPC::Server;


The Apache::RPC::Server module is a subclassing of RPC::XML::Server that is tuned and designed for use within Apache with mod_perl.

Provided are phase-handlers for the general request-processing phase (PerlHandler) and the child-process initialization phase (PerlChildInitHandler). The module should be loaded either by inclusion in a server start-up Perl script or by directives in the server configuration file (generally httpd.con). One loaded, the configuration file may assign the module to handle one or more given locations with the general set of <Location> directives and familiar options. Additional configuration settings specific to this module are detailed below.

Generally, externally-available methods are provided as files in the XML dialect explained in RPC::XML::Server. A subclass derived from this class may of course use the methods provided by this class and its parent class for adding and manipulating the method table.


This module is designed to be dropped in with little (if any) modification. The methods that the server publishes are provided by a combination of the installation files and Apache configuration values. Details on remote method syntax and semantics is covered in RPC::XML::Server.


In addition to inheriting all the methods from RPC::XML::Server, the following methods are either added or overloaded by Apache::RPC::Server:


This is the default content-handler routine that mod_perl expects when the module is defined as managing the specified location. This is provided as a method handler, meaning that the first argument is either an object reference or a static string with the class name. This allows for other packages to easily subclass Apache::RPC::Server.

This routine takes care of examining the incoming request, choosing an appropriate server object to actually process the request, and returning the results of the remote method call to the client.


This is another Apache-level handler, this one designed for installation as a PerlChildInitHandler. At present, its only function is to iterate over all server object currently in the internal tables and invoke the child_started method (detailed below) on each. Setting this handler assures that each child has a correct impression of when it started as opposed to the start time of the server itself.

Note that this is only applied to those servers known to the master Apache process. In most cases, this will only be the default server object as described above. That is because of the delayed-loading nature of all servers beyond the default, which are likely only in child-specific memory. There are some configuration options described in the next section that can affect and alter this.


This is the class constructor. It calls the superclass new method, then performs some additional steps. These include installing the default methods (which includes an Apache-specific version of system.status), adding the installation directory of this module to the method search path, and adding any directories or explicitly-requested methods to the server object.

This version of new expects the argument list to follow one of two patterns: it is either a single token "set-default", which creates and initializes the default server, or it has the following elements (in order):

        Apache class instance (reference)
        Server ID string of the server being created
        Prefix (if any) to be applied to the configuration values fetched
        (All remaining arguments are passed unchanged to C<SUPER::new()>)

The server identification string and prefix concepts are explained in more detail in the next section.


This method is very similar to the started method provided by RPC::XML::Server. When called with no argument or an argument that evaluates to a false value, it returns the UNIX-style time value of when this child process was started. Due to the child-management model of Apache, this may very well be different from the value returned by started itself. If given an argument that evaluates as true, the current system time is set as the new child-start time.

If the server has not been configured to set this at child initialization, then the main started value is returned. The name is different so that a child may specify both server-start and child-start times with clear distinction.


This method behaves exactly like the RPC::XML::Server method, save that the version string returned is (surprisingly enough) for this module instead.

Apache configuration semantics

In addition to the known directives such as PerlHandler and PerlChildInitHandler, configuration of this system is controlled through a variety of settings that are manipulated with the PerlSetVar and PerlAddVar directives. These variables are:


Sets a prefix string to be applied to all of the following names before trying to read their values. Useful for setting within a <Location> block to ensure that no settings from a higher point in the hierarchy influence the server being defined.

RpcServer [STRING]

Specify the name of the server to use for this location. If not passed, then the default server is used. This server may also be explicitly requested by the name "<default>". If more than one server are going to be created within the same Apache environment, this setting should always be used outside the default area so that the default server is not loaded down with extra method definitions. If a sub-location changes the default server, those changes will be felt by any location that uses that server.

Different locations may share the same server by specifying the name with this variable. This is useful for managing varied access schemes, traffic analysis, etc.

RpcServerDir [DIRECTORY]

This variable specifies directories to be scanned for method *.xpl files. To specify more than one directory, separate them with ":" just as with any other directory-path expression. All directories are kept (in the order specified) as the search path for future loading of methods.

RpcServerMethod [FILENAME]

This is akin to the directory-specification option above, but only provides a single method at a time. It may also have multiple values separated by colons. The method is loaded into the server table. If the name is not an absolute pathname, then it is searched for in the directories that currently comprise the path. The directories above, however, have not been added to the search path yet. This is because these directives are processed immediately after the directory specifications, and thus do not need to be searched. This directive is designed to allow selective overriding of methods in the previously-specified directories.

RpcDefMethods [YES|NO]

If specified and set to "no" (case-insensitive), suppresses the loading of the system default methods that are provided with this package. The absence of this setting is interpreted as a "yes", so explicitly specifying such is not needed.

RpcAutoMethods [YES|NO]

If specified and set to "yes", enables the automatic searching for a requested remote method that is unknown to the server object handling the request. If set to "no" (or not set at all), then a request for an unknown function causes the object instance to report an error. If the routine is still not found, the error is reported. Enabling this is a security risk, and should only be permitted by a server administrator with fully informed acknowledgement and consent.

RpcNoAutoUpdate [YES|NO]

(Not yet implemented) If specified and set to "yes", enables the checking of the modification time of the file from which a method was originally loaded. If the file has changed, the method is re-loaded before execution is handed off. As with the auto-loading of methods, this represents a security risk, and should only be permitted by a server administrator with fully informed acknowledgement and consent.

RpcDebugLevel [NUMBER]

Enable debugging by providing a numerical value that will be used as the debug setting by the parent class, RPC::XML::Server.

Specifying methods to the server(s)

Methods are provided to an Apache::RPC::Server object in three ways:

Default methods

Unless suppressed by a RpcDefMethods option, the methods shipped with this package are loaded into the table. The Apache::RPC::Server objects get a slightly different version of system.status than the parent class does.

Configured directories

All method files (those ending in a suffix of *.xpl) in the directories specified in the relevant RpcMethodDir settings are read next. These directories are also (after the next step) added to the search path the object uses.

By specific inclusion

Any methods specified directly by use of RpcMethod settings are loaded last. This allows for them to override methods that may have been loaded from the system defaults or the specified directories.

If a request is made for an unknown method, the object will first attempt to find it by searching the path of directories that were given in the configuration as well as those that are part of the system (installation-level directories). If it is still not found, then an error is reported back to the requestor. By using this technique, it is possible to add methods to a running server without restarting it. It is a potential security hole, however, and it is for that reason that the previously-documented RpcNoNewMethods setting is provided.


All methods return some type of reference on success, or an error string on failure. Non-reference return values should always be interpreted as errors unless otherwise noted.

Where appropriate, the log_error method from the Apache package is called to note internal errors.


This is a reference implementation in which clarity of process and readability of the code took precedence over general efficiency. Much, if not all, of this can be written more compactly and/or efficiently.


The XML-RPC standard is Copyright (c) 1998-2001, UserLand Software, Inc. See <http://www.xmlrpc.com> for more information about the XML-RPC specification.


This module is licensed under the terms of the Artistic License that covers Perl itself. See <http://language.perl.com/misc/Artistic.html> for the license itself.


RPC::XML::Server, RPC::XML


Randy J. Ray <rjray@blackperl.com>