daveime has asked for the wisdom of the Perl Monks concerning the following question:
use Time::HiRes qw ( gettimeofday tv_interval setitimer ITIMER_REAL ); use DBI; $ConnectTimeOut = 0.2; # 200 milliseconds ... $ConnectRetrys = 5; $ConnectAttempts = 0; $Handle = ""; while (($ConnectAttempts < $ConnectRetrys) && ($Handle eq "")) { eval { local $SIG{ALRM} = sub { die "DB CONN FAIL" }; setitimer(ITIMER_REAL, $ConnectTimeOut); $Handle = DBI->connect( "DBI:mysql:mydatabase;host=111.111.111 +.111;port=3306","myusername","mypassword",{ RaiseError => 1}); setitimer(ITIMER_REAL, 0); }; if ($@ and $@ =~ /DB CONN FAIL/) { print "CONNECT TIMED OUT\n"; $ConnectAttempts++; } if ($@ and $@ !~ /DB CONN FAIL/) { print "SOME OTHER CONNECTION PROBLEM\n"; $ConnectAttempts++; } if (!$@) { print "CONNECT IS GOOD\n"; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: DBI TimeOuts
by kesterkester (Hermit) on Jun 22, 2004 at 19:49 UTC | |
by daveime (Novice) on Jun 25, 2004 at 18:11 UTC |