Anyone has experience using the DBIx::Connector module for FastCGI pages? I googled around for a Perl implementation of DB Connection Pooling and found this DBIx::Connector module on CPAN which seems like it can be used for such functionality on FastCGI web pages. If you already had some experience using it, could you help clarifying some questions based on a sample script below? Any insight is greatly appreciated!
- The global scoped
$connobject is thread-safe and shared among all http's GET request threads inside the while loop ? - In each individual http's GET request thread, the
$conn->dbh()method will either:
a. Return/Re-use an existing$dbhobj. if it already exists. OR:
b. Instantiate and return a brand new$dbhobj. if there's no existing ones? - In the case the DB server goes down and then goes back up, which causes
$connto disconnect, how do we re-establish/re-activate this global$connobject ? ( from what I understand about FastCGI, all global vars. above the while loop only get declared once on web-server startup, and only those inside the while loop are declared for every http GET request.. )
Example code:
use CGI::Fast;
use DBIx::Connector;
# Global var. for all http GET request threads
my $conn = DBIx::Connector->new( $dsn, $username, $password, {
RaiseError => 1,
AutoCommit => 1,
});
# Handling individual http GET request thread
while ( $q = CGI::Fast->new ) {
my $dbh = $conn->dbh ;
my $cursor1 = $dbh->prepare( sqlString1 ) ;
$cursor1->execute() ;
my $cursor2 = $dbh->prepare( sqlString2 ) ;
$cursor2->execute() ;
...
} #end individual http GET request thread