I've never done this, but Ron's advice ($SIG{ALRM}) is in line with the DBI perldocs.
Here is a snippet from 'perldoc DBI' - I searched for "timeout": Signal Handling and Canceling Operations The first thing to say is that signal handling in Perl is currently *not* safe. There is always a small risk of Perl crashing and/or core dumping when, or after, handling a signal. (The risk was reduced with 5.004_04 but is still present.) The two most common uses of signals in relation to the DBI are for canceling operations when the user types Ctrl-C (interrupt), and for implementing a timeout using "alarm()" and $SIG{ALRM}. To assist in implementing these operations, the DBI provides a "cancel" method for statement handles. The "cancel" method should abort the current operation and is designed to be called from a signal handler. However, it must be stressed that: a) few drivers implement this at the moment (the DBI provides a default method that just returns "undef"); and b) even if implemented, there is still a possibility that the statement handle, and possibly the parent database handle, will not be usable afterwards. If "cancel" returns true, then it has successfully invoked the database engine's own cancel function. If it returns false, then "cancel" failed. If it returns "undef", then the database engine does not have cancel implemented. HTH. Hardy Merrill >>> "Reidy, Ron" <[EMAIL PROTECTED]> 01/20/05 12:08 PM >>> You could set up a SIG{ALARM} and the attempt the connection. Or better still, get your DBAs to fix the problems in the DBs. ----------------- Ron Reidy Lead DBA Array BioPharma, Inc. -----Original Message----- From: David Goodman [mailto:[EMAIL PROTECTED] Sent: Thursday, January 20, 2005 10:01 AM To: dbi-users@perl.org Subject: DBI connections to oracle sometimes hang On occassions when an oracle instance is having trouble, my DBI connections hang. For example, if the oracle archive log destination is full or the OS itself is hung, the DBI connection will also hang. With DBI's trace level 3, it remains hung on the following: -> connect for DBD::Oracle::dr (DBI::dr=HASH(0x40245c28)~0x4055c1f4 'DS1' 'su' **** HASH(0x40553c28)) The program itself connects to a list of Oracle servers and works fine except when the oracle instance itself is in difficulties. This stops the processing of the rest of the list, and does not even return an error message. At this site, there are a number of perl programs performing various functions across multiple dataservers. This issue has surfaced with Oracle but not with Sybase. Is there a way to have connections timeout when they do not respond? regareds, David This electronic message transmission is a PRIVATE communication which contains information which may be confidential or privileged. The information is intended to be for the use of the individual or entity named above. If you are not the intended recipient, please be aware that any disclosure, copying, distribution or use of the contents of this information is prohibited. Please notify the sender of the delivery error by replying to this message, or notify us by telephone (877-633-2436, ext. 0), and then delete it from your system.