How to set DBI connection timeout for Win32 Perl->MySQL ?
am 13.10.2007 17:44:23 von roadrunnerHi,
I'm struggling to set a timeout value for a DB connection from Perl
DBI to MySQL on Win32. No matter what I try it always seems to default
to timing out after around 23 seconds (I'm testing to a machine which
is not responding to ping to simulate a network failure).
I've tried setting the "mysql_connect_timeout" value as below but this
seems to make no difference:
$dbh = DBI->connect("DBI:mysql:db_name:db_host:3306;mysql_connect_t i
+meout=5","username","password");
I've also tried wrapping the code block in an alarm as below, but
again this makes no difference (note the alarm function seems to work
fine when I test it with other commands):
eval {
local $SIG{ALRM} = sub { die "connect timeout\n" };
alarm 5;
$dbHandle = DBI->connect("DBI:mysql:db_name:db_host:3306","username
+","password") or die $DBI::errstr;
alarm 0;
};
if ($@) {
# Timed out
die unless $@ eq "connect timeout\n";
}
Can anyone either see any problems with this code or suggest
alternative ways of doing this ?
I'm using ActiveState Perl v5.8.8 (build 822) on Win32 with DBI v1.58
and DBD-MySQL v4.005
Thanks,
Roadrunner.