Marcello has asked for the wisdom of the Perl Monks concerning the following question:
I use a timeout on the database connect, the parameters to the DBI->connect routine are OK. Almost always the connection is succesful, but sometimes this line shows up in the logfile:sub db_connect { my $self = shift; my $errStr; my $testStr; my $dbh; eval { local $SIG{ALRM} = sub { die "timeout\n" }; # NB: \n required alarm 10; $dbh = DBI->connect("DBI:mysql:".$self->{DB_NAME}.":".$self->{ +DB_HOSTNAME}.":".$self->{DB_PORT}, $self->{DB_USERNAME}, $self->{DB_P +ASSWORD}, { PrintError => 0 }); if (defined($dbh)) { $testStr = "[Database handle SET]"; } else { $errStr = "Unable to connect to database: ".$DBI::errstr; $testStr = "[Database handle NOT SET]"; } alarm 0; }; if ($@ eq "timeout\n") { # Timeout $errStr = "Connection to database timed out"; } elsif ($@) { # Unknown error $errStr = "Unknown error: ".$@; } my $result = defined($dbh); if (!$result) { $errStr .= " [dbh DEFINED]".$testStr; } else { $errStr .= " [dbh UNDEFINED]".$testStr; $self->log_comment("ERROR: db_connect => ".$errStr); } return $result; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: DBI connect problem
by Ovid (Cardinal) on Jul 30, 2002 at 20:27 UTC | |
|
Re: DBI connect problem
by hiseldl (Priest) on Jul 30, 2002 at 20:33 UTC | |
by IlyaM (Parson) on Jul 31, 2002 at 08:02 UTC | |
|
Re: DBI connect problem
by Cine (Friar) on Jul 30, 2002 at 20:25 UTC |