PHP快速排查定位问题

方法一、服务器日志

ps aux | grep nginx  //执行命令看主进程master process,有nginx的安装位置和配置文件的位置

/usr/sbin/nginx -t    //获取当前配置nginx.config 配置文件位置

tail -f /var/log/nginx/t3.local-error.log  //查看错误日志

方法二、

phpinfo();  找到配置文件,找到错误日志,开启报错级别,查看错误日志;

找到display_errors = On;

error_reporting=E_ALL &  ~E_NOTICE;

方法三、

跟踪路由找到入口文件,浏览器打印调试问题;

数据库开启打印查看写入SQL情况

#查看日志情况
show variables like '%general%';
#开启日志
SET GLOBAL general_log = 'On';
#指定日志文件
SET GLOBAL general_log_file = '/var/lib/mysql/mysql.log';

方法四、

####
#### 通过回溯函数定位文件错误位置
#### register_shutdown_function
####
<?php

/**
* 公共返回封装
* Class CommonReturn
*/
class CommonReturn
{

/**
* 打包函数
* @param $params
* @param int $status
*
* @return mixed
*/
static public function packData($params, $status = 0)
{
ob_start();
//打印了一条 PHP 回溯
debug_print_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 5);
//得到当前缓冲区的内容并删除当前输出缓
$trace = ob_get_clean();
register_shutdown_function(array('CommonReturn','handleFatal'), $trace);
//register_shutdown_function(function(){
//var_dump(error_get_last());
//});
        $res['status'] = $status;
$res['data'] = json_encode($params);
return $res;
}

/**
* 错误处理
* @param $trace
*/
static public function handleFatal($trace)
{
//获取最近发生的错语
$err = error_get_last();
if ($err['type']) {
$log_cont = 'time=%s' . PHP_EOL . 'error_get_last:%s' . PHP_EOL . 'trace:%s' . PHP_EOL;
@file_put_contents('/tmp/debug_' . __FUNCTION__ . '.log', sprintf($log_cont, date('Y-m-d H:i:s'), var_export($err, 1), $trace), FILE_APPEND);
}

}
}
$CommonReturn = new CommonReturn;
$data = $CommonReturn::packData([1],1);
var_dump($data);
exit;

猜你喜欢

转载自www.cnblogs.com/shineen/p/13370566.html
今日推荐