Re: SIGALRM blocked by MySQL
Solution - The below works from the command line and within Apache 2. You have to re-establish your Database handle if you experience a timeout.
I am only using this on SELECT statements. I doubt you'll want to do this on INSERTs or UPDATEs.
I tried using $sth->cancel instead of die, but $sth was undefined by the time it got there.
Keywords: SIGALRM perl alarm timed query
======================================================================
use Sys::SigAction qw( set_sig_handler );
eval {
my $h = set_sig_handler( 'ALRM' ,sub { $canceled = 1; die; }
,{ mask=>[ qw( INT ALRM ) ] ,safe => 0 }
);
alarm(5);
$sth = &SQL("SELECT keycol from big_tab_test where keycol > 10");
alarm 0;
};
if ( $@ ) {
if ( not $@ =~ m/Die/i ) {
print "Non Timeout error: $@\n";
} else {
print "Timed out\n";
$dbh = ''; $dbh = &open_database(); # necessary if run from Apache
}
} else {
print "No Error\n";
}
Edited 3 time(s). Last edit at 04/06/2009 06:07PM by Patrick Hollins.
Subject
Written By
Posted
Re: SIGALRM blocked by MySQL
April 06, 2009 02:40PM
Sorry, you can't reply to this topic. It has been closed.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.