PHP自定义函数设置超时间
/**
* selfTunTimeout
* @desc 监控函数超时
* @author 陈修超
* @time 2017年9月27日
* @param $time
* @param $fun
* @param $param
*/
public static function selfTunTimeout($time,$fun,$param){
$fun = __CLASS__."::$fun";
try{
pcntl_alarm($time);
pcntl_signal(SIGALRM, "self::throwExp");
$res = call_user_func($fun,$param);
pcntl_alarm(0);
}catch(Exception $e){
echo "$fun TIMEOUT".PHP_EOL;
}
var_dump($res);exit;
return $res;
}
/**
* throwExp
* @desc 抛出异常
* @throws Exception
*/
public static function throwExp(){
throw new Exception;
}