local our $dbh = DBI->connect ("DBI:mysql:database=$db:host=$mysqlhost","user","pass") || die "Can't connect to database: $DBI::errstr\n"; $dbh->{RaiseError} = 1; local our $sth = $dbh->prepare ( "SELECT this from that;"); # Start of cronometer local our $t0; local our $t1; local our $elapsed; $t0 = gettimeofday; ######################### # Start of timeout ##### eval { local $SIG{ALRM} = sub { die "Sorry, time's up.\n" }; alarm 1; # some operation that might take a long time to complete ######################### ######################### $sth->execute( ); # sleep 3; ######################### alarm 0; }; die $@ if $@; ######################### # End of timeout ######## # end of cronometer $t1 = gettimeofday; $elapsed = $t1 - $t0; print "Content-type: text/html\n\n"; print "Query took $elapsed seconds but the alarm didn't work!";