美文网首页
PHP自定义函数设置超时间

PHP自定义函数设置超时间

作者: 晓得为_ | 来源:发表于2017-11-06 16:09 被阅读0次

    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;
    }

    相关文章

      网友评论

          本文标题:PHP自定义函数设置超时间

          本文链接:https://www.haomeiwen.com/subject/lwyuextx.html