使用场景,服务器报异常错误,想要及时收到报警信息并处理
环境介绍,本博使用yaf框架+php,仅仅提供思路,参考,具体根据自己实际情况进行编写
1,每十分钟执行一次任务脚本
# 每10分钟执行一次的任务
if [ "0" -eq "$(($minute % 10))" ]; then
php -f ${pathRoot}public/index.php 'request_uri=/error/dingdingLog'
fi
/**
* error action
*
* @return bool
* @throws Exception
*/
public function errorAction()
{
$req = $this->getRequest();
$exception = $req->getException();
//来自接口的错误
if ($exception instanceof ApiException) {
return $this->json($exception->getCode(), $exception->getMessage());
}
//其它异常
if ($this->yafAutoRender) {
$exceptions = [];
if (! $exception instanceof Exception) {
$exc