Please be specific to the 2 cases that I mentioned and tell me how can we tell which case's signals are safe and which case's are not, and most importantly WHY.
CASE 1:
#!/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;
CASE 2:
#!/usr/bin/perl
$max_time = 5;
$timeout = 3;
use DBI;
print "Content-type: text/html\n\n";
sub do_counter {
$time1 = time;
$time2 = time;
$counter = 0;
$time_ran = $time2 - $time1;
$dbh=DBI->connect("dbi:mysql:$database:localhost","username","pass
word");
$query="SELECT name FROM test";
$sth=$dbh->prepare($query);
$sth->execute();
while ( @row = $sth->fetchrow_array ) {
while($time_ran <= $max_time) {
$conter++;
$time2 = time;
$time_ran = $time2 - $time1;
}
}
$sth->finish;
$dbh->disconnect ||die("Couldn't disconnect to database!\n");
}
eval {
local $SIG{ALRM} = sub { die "alarm\n" };
alarm $timeout;
&do_counter;
alarm 0;
};
if($@) {
print "$@, Time Ran: $time_ran, Counter: $conter\n";
exit;
}
print "Time Ran: $time_ran, Counter: $conter\n";
exit;
NOTES: I've a feeling you don't understand the issue in the thread, simply making empty statement.
|