Greetings,
 
    I am having a problem with a module im writing connecting to the database everytime its run, and not cleaning up the database connection when its finished. I have tried the 2 scenarios below and as yet i cannot work out how to stop the connections building up and eventually causing mysqld to crash.
 
Scenario 1:
 
in the script:  (NB: this is not the entire script.. just snippets to show what im trying to achive).
 
use strict;
use vars ($dbh);
 
use mod_perl;                                                    
use DBI;
 
sub config {
.............
 
    $dbh ||= &dbi_connect;
}
 
sub dbi_connect {
        my $an = $C{'auth_name'};
        my $dbh = DBI->connect("$C{$an}{'TicketDB'}", "$C{$an}{'TicketDBUser'}", "$C{$an}{'TicketDBPassword'}")
                or die "Couldn't connect to database: $!";
        return $dbh;
}
 
sub login_handler {
    my ($self, $r) = @_;
    &config($r);
    ........
}
 
1;
 
END {
    $dbh->disconnect;
}
 
 
 
Scenario 2:
 
same script as above, except Apache::DBI was used... the result is the same.. the database connections just keep building up.
 
 
Please help, i dont know if i have been descriptive enough about the problem. But I need to resolve this, as when the site gets a few visits.. mysql and apache crash from having too many connections to the database.
 
DJ
Webmastery.

Reply via email to