Feb 12, 2003 #1 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();
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();
Feb 13, 2003 1 #2 highs008 Programmer Nov 29, 2001 18 NL //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(); ?> Upvote 0 Downvote
//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(); ?>