#!/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;
#!/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;
In reply to Re^12: Perl Alarm Not Working
by aceofspace
in thread Perl Alarm Not Working
by aceofspace
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |