Table 1.
The Phases of mod_perl
Lincold Stein and Doug MacEachern

"Stately Scripting with mod_perl"
The Perl Journal, Spring 1998
 
  1. Module initialization (directives: PerlModule, PerlRequire)
    Called once in the parent server, during startup and restarts. This is where the interpreter object is constructed.
  2. Reading the configuration file (directive: <Perl>...</Perl>)
    Called by the parent server during startup and restarts to read the server configuration files. Also called when .htaccess files are found at request time.
  3. Child initialization (directive: PerlChildInitHandler)
    Called when a new Apache process has been launched.
  4. Post read request (directive: PerlPostReadRequestHandler)
    Called after the client request has been read, but before any other processing has been performed. Here's where you can examine HTTP headers and change them before Apache gets a crack at them.
  5. URI translation (directive: PerlTransHandler)
    Called to perform the translation between the virtual URI and the physical filename. For example, you can use this to override the way that Apache translates URIs into paths in the document root, or to perform fancy string mappings.
  6. Header parsing (directive: PerlHeaderParserHandler)
    Now that the URI has been mapped to a resource, the module is given another chance to look at the request. Here it can decide if the request structure needs to be modified in some way or terminated altogether before the server performs resource-intensive tasks.
  7. Access control (directive: PerlAccessHandler)
    When a URL is under access control (access restriction that does not require user authentication such as a password), PerlAccessHandler() is called. This lets you contrive your own restrictions for a directory, such as restricting access based on the day of the week or phase of the moon.
  8. Authentication (directive: PerlAuthenHandler)
    When invoked, this phase determines whether the user is who he says he is (by username and password).
  9. Authorization (directive: PerlAuthzHandler)
    This phase decides whether the user is permitted to access this particular URI.
  10. MIME type mapping (directive: PerlTypeHandler)
    This phase maps URIs to MIME types. You can use this to override Apache's default file extension to MIME type mappings. For example, you could look the MIME type up in a database, or infer it from the file's "magic number."
  11. Miscellaneous fixups (directive: PerlFixupHandler)
    This phase is invoked just before content generation so that modules can "fixup" the request now that it knows exactly who will handle the response. For example, this is where mod_env prepares the SetEnv and PassEnv configuration directives that show up in Perl's %ENV.
  12. Content generation (directive: PerlHandler)
    This is where you create HTML pages, redirections, or any other type of HTTP response. This is the most frequently handled phase of the transaction.
  13. Logging (directive: PerlLogHandler)
    Called after all the other phases to log the results. You can use this to customize Apache's log format, or to change logging completely. For example, you can compute summary statistics and store them to a relational database.
  14. Registered cleanups (directive: PerlCleanupHandler)
    Modules may register functions to be called after the client connection has been closed and just before the various request resources are cleaned up.
  15. Child exit (directive: PerlChildExitHandler)
    Called just before an Apache process terminates.