roadrunner has asked for the wisdom of the Perl Monks concerning the following question:
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:
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):$dbh = DBI->connect("DBI:mysql:db_name:db_host:3306;mysql_connect_ti +meout=5","username","password");
Can anyone either see any problems with this code or suggest alternative ways of doing this ?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"; }
I'm using ActiveState Perl v5.8.8 (build 822) on Win32 with DBI v1.58 and DBD-MySQL v4.005
Thanks,
Roadrunner.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How to set DBI connection timeout for Win32 Perl->MySQL ?
by erroneousBollock (Curate) on Oct 13, 2007 at 12:33 UTC | |
by roadrunner (Acolyte) on Oct 13, 2007 at 15:16 UTC | |
|
Re: How to set DBI connection timeout for Win32 Perl->MySQL ?
by Cop (Initiate) on Oct 13, 2007 at 15:59 UTC | |
by roadrunner (Acolyte) on Oct 13, 2007 at 17:44 UTC | |
|