Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

time out for whois script 1

Status
Not open for further replies.

farley99

MIS
Feb 12, 2003
413
US
hi,

i want to make a whois script, but i need it to time out if the whois is down.

Is there a way to set a time limit for a function inside a php page?

Can this be used for a function?
set_time_limit();
 
//GLOBALS
$RETURN_CHAR = "\n";
$TIMEOUT = 5; //number of seconds to timeout
$PID = getmypid();
$CHILD_PID = 0;

//Make sure program execution doesn't time out
set_time_limit(0);

function set_timeout() {
global $PID;
global $CHILD_PID;
global $TIMEOUT;

$CHILD_PID = pcntl_fork();
if($CHILD_PID == 0) {
sleep($TIMEOUT);
posix_kill($PID, SIGTERM);
exit;
}
}

function clear_timeout() {
global $CHILD_PID;
posix_kill($CHILD_PID, SIGTERM);
}

// your functions over here...

set_timeout();
... timeout protected function...
clear_timeout();


?>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top