The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Apache::BabyConnect - uses DBI::BabyConnect to initiate persistent database connections

SYNOPSIS

 # Configuration in perl.conf and startup.pl:

 PerlSetEnv BABYCONNECT /opt/DBI-BabyConnect/configuration
 PerlRequire /opt/Apache-BabyConnect/startupscripts/babystartup.pl

DESCRIPTION

This module initiates a persistent database connection using DBI::BabyConnect.

The database access uses Perl's DBI::BabyConnect. For a roadmap on using this module, see the README.TXT

When loading the Apache::BabyConnect module, the module looks if the environment variable BABYCONNECT has been set to the URI location where it can read the configuration files, and if the the module DBI::BabyConnect has been loaded. The startup script instantiates DBI::BabyConnect objects with caching and persistence enabled. Each object is connected to a data source as described by the descriptor.

If you create a DBI::BabyConnect object from a Perl script, then if the descriptor is found in the DBI::BabyConnect cache, you will be using the cached object. Otherwise, a new DBI::BabyConnect is created with that descriptor, and it is added to the cache.

Any Perl script use DBI::BabyConnect to create as many objects, however, DBI::BabyConnect will only create a new object if not found in the cache. Programmers do not need to keep track of what is being cached, and they can write code as if the script is to be run from the command prompt.

Unlike the Apache::DBI module, there is no request forwarding between the DBI module and the Apache::BabyConnect. All caching is handled by the DBI::BabyConnect. Do not load the Apache::DBI module whenever you are using Apache::BabyConnect, otherwise you will imply a penalty on the caching mechanism, and you will be limited to the caching mechanism of Apache::DBI.

The Apache::BabyConnect module does not have the same limitation as Apache::DBI. DBI::BabyConnect objects are persisted on per process basis, and a user can access several times a database from different http servers. The Apache::BabyConnect objects will never share the same handle. Each Apache::BabyConnect object contains its own handle, and DBI::db handle are never cached or shared. For this reason you should not load the Apache::DBI module.

Caching of the Apache::BabyConnect is maintained within the DBI::BabyConnect module itself, and the each entry in the cache is uniquely identified by the concatenation of: the kernel process number of the http server + the database descriptor.

CONFIGURATION

Before loading the module, you need to setup the BABYCONNECT environment variable to point to the DBI::BabyConnect configuration directory. After, setting the environment variable BABYCONNECT, you should load the Apache::BabyConnect upon startup of the Apache daemon.

Add the following line to your perl.conf:

 PerlSetEnv BABYCONNECT /p9/BABYCONNECT/DBI-BabyConnect/configuration
 PerlRequire /p9/BABYCONNECT/Apache-BabyConnect/startupscripts/babystartup.pl

Write a startup script to be loaded via the PerlRequire directive. For example, the "babystartup.pl". PerlModule Apache::DBI

You do not need to load the DBI module.

There is only one method call that you need to use to achieve a persistent connection upon server startup:

 Apache::BabyConnect->connect_on_init($datasource_descriptor [,$stderr_log] [,$trace_log] [,$trace_level]);

babystartup.pl

use strict;

$ENV{MOD_PERL} or die "not running under mod_perl!";

 use ModPerl::Registry ();
 use LWP::UserAgent ();

 use Apache::BabyConnect ();

 use Carp ();
 $SIG{__WARN__} = \&Carp::cluck;

 $Apache::BabyConnect::DEBUG = 2;

 #ATTENTION: this is only a sample example to test with Apache::BabyConnect,
 #  in production environment, do not enable logging and tracing. To do so
 #  just call connect_on_init() with the database descriptor only. For example:
 #Apache::BabyConnect->connect_on_init('BABYDB_001');

 Apache::BabyConnect->connect_on_init(
        'BABYDB_001',
        '/var/www/htdocs/logs/error_BABYDB_001.log',
        '/var/www/htdocs/logs/db_BABYDB_001.log',
        2
 );

 Apache::BabyConnect->connect_on_init(
        'BABYDB_002',
        '/var/www/htdocs/logs/error_BABYDB_002.log',
        '/var/www/htdocs/logs/db_BABYDB_002.log',
        2
 );

 Apache::BabyConnect->connect_on_init(
        'BABYCONNECT_003',
        '/var/www/htdocs/logs/error_BABYDB_003.log',
        '/var/www/htdocs/logs/db_BABYDB_003.log',
        2
 );

 Apache::BabyConnect->connect_on_init(
        'BABYCONNECT_004',
        '/var/www/htdocs/logs/error_BABYDB_004.log',
        '/var/www/htdocs/logs/db_BABYDB_004.log',
        2
 );

 1;

PREREQUISITES

MOD_PERL 2.0

Apache::DBI version 0.96 and higher should work under mod_perl 2.0 RC5 and later with httpd 2.0.49 and later.

MOD_PERL 1.0 Note that this module needs mod_perl-1.08 or higher, apache_1.3.0.

SEE ALSO

DBI::BabyConnect, DBI

AUTHORS

  • Bassem W. Jamaleddine is the original author of Apache::BabyConnect.

  • mod_perl by Doug MacEachern.

  • DBI by Tim Bunce <dbi-users-subscribe@perl.org>

COPYRIGHT

The Apache::BabyConnect module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

2 POD Errors

The following errors were encountered while parsing the POD:

Around line 352:

'=item' outside of any '=over'

Around line 361:

You forgot a '=back' before '=head1'