in reply to Re^7: Perl Alarm Not Working
in thread Perl Alarm Not Working
#!/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"," +password"); $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;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^9: Perl Alarm Not Working
by ikegami (Patriarch) on Dec 21, 2010 at 17:34 UTC | |
|
Re^9: Perl Alarm Not Working
by Anonymous Monk on Dec 21, 2010 at 12:34 UTC | |
by aceofspace (Acolyte) on Dec 21, 2010 at 13:04 UTC | |
by Anonymous Monk on Dec 21, 2010 at 13:34 UTC | |
by aceofspace (Acolyte) on Dec 21, 2010 at 15:50 UTC | |
by ikegami (Patriarch) on Dec 21, 2010 at 17:38 UTC |