Some of my perl modules connect to the database during startup, and I
have been getting errors when my children try to connect to the
database, because they end up trying to share the $dbh handles from the
parent.

The current code that tries to prevent handle caching (according to the
comments) doesn't do anything except avoid creating connections the
first time the server is started.

    if (MP2) {
        require Apache2::ServerUtil;
        if (Apache2::ServerUtil::restart_count() == 1) {
            print STDERR "....."
        }
    }

However, the server immediately stops and starts again, and all the
handles created in the parent are cached and then shared out to the
children.

And when the server is restarted, the restart_count just keeps going up
- there is now way that I can see of knowing if you are in a restart or
not.

So I thought of pushing a PerlPostConfigHandler which clears the cached
connections.  Hope the patch is in the right format:

--- Apache/DBI.pm       2006-01-29 00:52:50.000000000 +0100
+++ Apache/DBI.pm.new   2006-01-29 00:54:03.000000000 +0100
@@ -11,6 +11,8 @@
         require mod_perl2;
         require Apache2::Module;
         require Apache2::ServerUtil;
+        my $s = Apache2::ServerUtil->server;
+        $s->push_handlers(PerlPostConfigHandler => \&clearconnections);
     }
     elsif (defined $modperl::VERSION && $modperl::VERSION > 1 &&
         $modperl::VERSION < 1.99) {
@@ -198,6 +200,14 @@
     1;
 }

+# The PerlPostConfigHandler clears any connections created during
+# startup so that handles are not shared between children
+sub clearconnections {
+    my $prefix = "$$ Apache::DBI            ";
+    print STDERR "$prefix PerlPostConfigHandler \n" if $Apache::DBI::DEBUG > 1;
+    %Connected = ();
+    0;
+}

 # The PerlCleanupHandler is supposed to initiate a rollback after the script 
has finished if AutoCommit is off.
 # Note: the PerlCleanupHandler runs after the response has been sent to the 
client


Any reason why this is bad?

________________________________________________________________________

Clinton Gormley [EMAIL PROTECTED]

www.TravelJury.com - For travellers, By travellers



Reply via email to