You have something there that MySql is immune to SIGALRM.
Here's another test script I wrote to test SIGALRM in a script running MySql:
#!/usr/bin/perl
require 'myconfigure.cgi';
$timeout = 5;
use DBI;
$keywords = "Whether rocking natural-curls, a-short";
print "Content-type: text/html\n\n";
sub do_search {
$time1 = time;
$dbh=DBI->connect("dbi:mysql:$database:localhost","$username","$pa
+ssword");
$keywords_quoted = $dbh ->quote ($keywords);
$query="SELECT count(*) FROM $websites_table WHERE MATCH(title) AG
+AINST ($keywords_quoted)";
$sth=$dbh->prepare(qq{$query});
$sth->execute();
$total_count = $sth->fetchrow_array ();
$sth->finish;
$dbh->disconnect ||die("Couldn't disconnect to database!\n");
$time2 = time;
$time_ran = $time2 - $time1;
}
eval {
local $SIG{ALRM} = sub { die "alarm\n" };
alarm $timeout;
&do_search;
alarm 0;
};
if($@) {
$time2 = time;
$time_ran = $time2 - $time1;
print "$@, Time Ran: $time_ran, Total Count: $total_count\n";
exit;
}
print "Time Ran: $time_ran, Total Count: $total_count\n";
exit;
Above script basically do a search for the number of matches of $keywords in $websites_table. I've used a timeout of 5 seconds( $timeout = 5;) to limit the time of search, i.e. exit if search takes more than 5 seconds.
When it timeouts by the eval{} block, it will indicate how much time the script has ran as shown by the variable $time_ran in the if($@) loop.
But I'm getting funny results when it timeout. It overshoots the timeout limit of 5 sec condiderably. In one instance, I got a value of $time_ran = 18.
How do I fix this problem?
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.