View on
Edmund Mergl > ApacheDBI-0.71 > Apache::DBI



Annotate this POD

Related Modules

View/Report Bugs
Module Version: 0.71   Source   Latest Release: ApacheDBI-0.88


Apache::DBI - Initiate a persistent database connection


 # Configuration in httpd.conf or srm.conf

 PerlModule Apache::DBI


This module initiates a persistent database connection.

The database access uses Perl's DBI. For supported DBI drivers see:

When loading the DBI module it looks if the environment variable GATEWAY_INTERFACE starts with 'CGI-Perl' and if the module Apache::DBI has been loaded. In this case every connect request will be forwarded to the Apache::DBI module. This looks if a database handle from a previous connect request is already stored and if this handle is still valid using the ping method. If these two conditions are fulfilled it just returns the database handle. If there is no appropriate database handle or if the ping method fails, a new connection is established and the handle is stored for later re-use. There is no need to delete the disconnect statements from your code. They won't do anything because the Apache::DBI module hides the database handle.

The Apache::DBI module still has a limitation: it keeps database connections persistent on a per process basis. The problem is, if a user accesses several times a database, the http requests will be handled very likely by different httpd children. Every child process needs to do its own connect. It would be nice, if all httpd children could share the database handles. One possible solution might be a threaded Apache version.

With this limitation in mind, there are scenarios, where the usage of is depreciated. Think about a heavy loaded Web-site where every user connects to the database with a unique userid. Every httpd child would create many database handles each of which spawning a new backend process. In a short time this would kill the web server.

Another problem are timeouts: some databases disconnect the client after a certain time of inactivity. The module tries to validate the database handle using the new ping-method of the DBI-module. This method returns true as default. If the database handle is not valid and the driver module has no implementation for the ping method, you will get an error when accessing the database. As a work-around you can try to replace the ping method by any database command, which is cheap and safe.

This module plugs in a menu item for Apache::Status. The menu lists the current database connections. It should be considered incomplete because of the limitations explained above. It shows the current database connections for one specific httpd process, the one which happens to serve the current request. Other httpd children might have other database connections.


Apache(3), DBI(3)


 mod_perl by Doug MacEachern <>
 DBI by Tim Bunce <>
 Apache::DBI by Edmund Mergl <>
syntax highlighting: