getting closer...

liunx

Guest
i'm needing some help with a CGI. the concempt is simple, have a page updated manually and posted on a template via SSI, but have a dynamic time out script for ammount of time the update will display.

help save the monkey!
chris<pixelmonkey>:monkey:It seems you know about SSI and stuff, so here's code that'll do the timeout part for ya. I used this wrapper to check DNS and MX wrappers from PHP, which doesn't have a timeout for system calls.



$SIG{ALRM} = sub{die "timeout"};
$TIMEOUT = 2;# number of seconds to timeout after

$name = shift;
eval{
alarm($TIMEOUT);# throw alarm after $TIMEOUT seconds if not done

# do your stuff - you only have $TIMEOUT seconds!!



alarm(0);# reset alarm
};

if($@){
if($@ =~ /timeout/){
# You'll get here if you've timed out above
# handle the timeout as needed
print "timed out\n";
}else{
# no timeout - some other error
alarm(0);# reset alarm
}
}else{
# no error
print "success\n";
}


enjoy!
 
Back
Top