PHP内置方法
1、set_exception_handler(exceptionhandler); //设置用户定义的异常处理函数;
exceptionhandler规定当一个未捕获的异常发生时所调用函数的名称
2、set_error_handler(error_function,error_types) ;//设置用户自定义的错误处理函数, 该函数用于创建运行时期间的用户自己的错误处理方法
error_function 规定发生错误时运行的函数
YII框架下使用两个PHP的内置方法处理异常
Yii的具体处理
1、注册监听,脚本初始时进行设置,生命周期到结束
protected function initSystemHandlers()
{
if(YII_ENABLE_EXCEPTION_HANDLER)
set_exception_handler(array($this,'handleException'));//注册方法
if(YII_ENABLE_ERROR_HANDLER)
set_error_handler(array($this,'handleError'),error_reporting());
}
2、异常处理
public function handleException($exception)
{
restore_error_handler();//恢复原异常处理方式,避免错误嵌套
restore_exception_handler();
//其它的错误处理通知
try{
$this->end(1);
}
catch(Exception $e) {
error_log($msg); //写操作日志
exit(1);
}
}
Laravel的异步处理方式
https://xueyuanjun.com/post/7500.html