Show Contents Previous Page Next Page Chapter 3 - The Apache Module Architecture and API In this section...
When Apache calls a handler, it passes information about the current transaction and the server configuration. It's the handler's responsibility to take whatever action is appropriate for this phase and to then return an integer status code to Apache indicating the success or failure of its operation. Show Contents Go to Top Previous Page Next PageIn the Perl API, the definition of a handler is short and sweet: sub { my $r = shift; # do something return ; }
No matter which phase of the Apache life cycle the handler is responsible for, the subroutine structure is always the same. The handler is passed a single argument consisting of a reference to an Apache request object. The request object is an object-oriented version of a central C record structure called the request record, and it contains all the information that Apache has collected about the transaction. By convention, a typical handler will store this object in a lexically scoped variable named
There is one special case, however. If the handler has a function prototype of sub ($$) { my $class = shift; my $r = shift; # do something return ; } We give an example of using a Perl API method handler in the next chapter. Request handlers declared in the C API are very similar: static int (request_rec* r) { /* do something */ return ; }
The handler is called with a single argument consisting of a pointer to a However, unlike the Perl API, in which all handlers have the same structure regardless of their phase, the C API handlers that are responsible for the phases of the server life cycle outside the request loop are heterogeneous. For example, a child_init() handler in C looks like this: static void child_init (server_rec *s, pool *p) { /* do something */ } In this case, there is no request record because there is no request to process
at this point. Instead there is a pointer to a server record structure (a Copyright © 1999 by O'Reilly & Associates, Inc. |
HIVE: All information for read only. Please respect copyright! |