php网站打开访问慢,排查过程案例!
时间:2023年06月14日
/来源:网络
/编辑:佚名
问题描述:
客户反馈昨天网站访问还是正常的,今天访问特别慢,环境源码什么都没动过 请求需要1分钟

拿到机器资料后检查负载一切正常,查看客户使用的是宝塔linux面板,lnmp环境,可以通过slow log追踪到问题点
我们先来配置slow log,执行:vi /www/server/php/70/etc/php-fpm.conf #添加图两行
request_slowlog_timeout = 30
slowlog = var/logs/slow.log

说明:slowlog定义日志路径和名字,request_slowlog_timeout定义超时时间,单位秒,即一个php脚本执行时间超过了该时间,则会记录日志。
添加完成后重启php-fpm,需重启后生效 接受重新访问网站即会生成相关日志 如下:

[19-Mar-2020 08:15:46] [pool www] pid 31184
script_filename = /www/wwwroot/www.baidu.com/public/index.php
[0x00007fc46f0151f0] file_get_contents() /www/wwwroot/www.baidu.com/extend/hook/AccessAuth.php(75) : eval()’d code:3
[0x00007fc46f015070] [INCLUDE_OR_EVAL]() /www/wwwroot/www.baidu.com/extend/hook/AccessAuth.php:75
[0x00007fc46f014ff0] auth() /www/wwwroot/www.baidu.com/extend/hook/AccessAuth.php:43
[0x00007fc46f014b00] run() /www/wwwroot/www.baidu.com/framework/library/think/Hook.php:137
[0x00007fc46f0146c0] exec() /www/wwwroot/www.baidu.com/framework/library/think/Hook.php:95
[0x00007fc46f0144f0] listen() /www/wwwroot/www.baidu.com/framework/library/think/App.php:596
[0x00007fc46f013c70] module() /www/wwwroot/www.baidu.com/framework/library/think/App.php:456
[0x00007fc46f013940] exec() /www/wwwroot/www.baidu.com/framework/library/think/App.php:139
[0x00007fc46f013240] run() /www/wwwroot/www.baidu.com/framework/start.php:19
[0x00007fc46f0131b0] [INCLUDE_OR_EVAL]() /www/wwwroot/www.baidu.com/public/index.php:21
slow log,不仅记录哪一个文件慢,而且也可以记录具体哪一行的什么函数,从上面的日志看到都是程序层上的原因导致,未涉及数据库查询,看到file_get_contents()心中暗喜
file_get_contents()一般都是请求外部链接异常导致整体网站请求慢,为证实这一点找到AccessAuth.php文件75行 如下图:

查看php代码经过base64加密需要解密后方可以看到源码,如下:
try { if (cache(‘auth_domain’) !== 1) {
$c = file_get_contents(“https://xxxxxxxx.cn/api.php?m=auth&a=index&prj_id=5&domain={$_SERVER[‘HTTP_HOST’]}&vsign=联动发卡|lovecode/zidongfaka|12|weixiaobao|20190224170352”);
$res = json_decode($c, true);
if ($res == false || $res[‘status’] == -1) {
//exit(isset($res[‘info’]) ? $res[‘info’] : ‘未知错误 403-1’);
} cache(‘auth_domain’, 1, 3600);
} } catch (\Exception $e) {
//exit(isset($res[‘info’]) ? $res[‘info’] : ‘未知错误 403-2’);
}
多地请求xxxxxxxx.cn网站异常,ping不通 那么问题很可能就出现在这 尝试注释上述代码再次访问响应恢复正常
希望你参考该教程能帮助你更快找到问题所在并解决
客户反馈昨天网站访问还是正常的,今天访问特别慢,环境源码什么都没动过 请求需要1分钟

拿到机器资料后检查负载一切正常,查看客户使用的是宝塔linux面板,lnmp环境,可以通过slow log追踪到问题点
我们先来配置slow log,执行:vi /www/server/php/70/etc/php-fpm.conf #添加图两行
request_slowlog_timeout = 30
slowlog = var/logs/slow.log

说明:slowlog定义日志路径和名字,request_slowlog_timeout定义超时时间,单位秒,即一个php脚本执行时间超过了该时间,则会记录日志。
添加完成后重启php-fpm,需重启后生效 接受重新访问网站即会生成相关日志 如下:

[19-Mar-2020 08:15:46] [pool www] pid 31184
script_filename = /www/wwwroot/www.baidu.com/public/index.php
[0x00007fc46f0151f0] file_get_contents() /www/wwwroot/www.baidu.com/extend/hook/AccessAuth.php(75) : eval()’d code:3
[0x00007fc46f015070] [INCLUDE_OR_EVAL]() /www/wwwroot/www.baidu.com/extend/hook/AccessAuth.php:75
[0x00007fc46f014ff0] auth() /www/wwwroot/www.baidu.com/extend/hook/AccessAuth.php:43
[0x00007fc46f014b00] run() /www/wwwroot/www.baidu.com/framework/library/think/Hook.php:137
[0x00007fc46f0146c0] exec() /www/wwwroot/www.baidu.com/framework/library/think/Hook.php:95
[0x00007fc46f0144f0] listen() /www/wwwroot/www.baidu.com/framework/library/think/App.php:596
[0x00007fc46f013c70] module() /www/wwwroot/www.baidu.com/framework/library/think/App.php:456
[0x00007fc46f013940] exec() /www/wwwroot/www.baidu.com/framework/library/think/App.php:139
[0x00007fc46f013240] run() /www/wwwroot/www.baidu.com/framework/start.php:19
[0x00007fc46f0131b0] [INCLUDE_OR_EVAL]() /www/wwwroot/www.baidu.com/public/index.php:21
slow log,不仅记录哪一个文件慢,而且也可以记录具体哪一行的什么函数,从上面的日志看到都是程序层上的原因导致,未涉及数据库查询,看到file_get_contents()心中暗喜
file_get_contents()一般都是请求外部链接异常导致整体网站请求慢,为证实这一点找到AccessAuth.php文件75行 如下图:

查看php代码经过base64加密需要解密后方可以看到源码,如下:
try { if (cache(‘auth_domain’) !== 1) {
$c = file_get_contents(“https://xxxxxxxx.cn/api.php?m=auth&a=index&prj_id=5&domain={$_SERVER[‘HTTP_HOST’]}&vsign=联动发卡|lovecode/zidongfaka|12|weixiaobao|20190224170352”);
$res = json_decode($c, true);
if ($res == false || $res[‘status’] == -1) {
//exit(isset($res[‘info’]) ? $res[‘info’] : ‘未知错误 403-1’);
} cache(‘auth_domain’, 1, 3600);
} } catch (\Exception $e) {
//exit(isset($res[‘info’]) ? $res[‘info’] : ‘未知错误 403-2’);
}
多地请求xxxxxxxx.cn网站异常,ping不通 那么问题很可能就出现在这 尝试注释上述代码再次访问响应恢复正常
希望你参考该教程能帮助你更快找到问题所在并解决
新闻资讯 更多
- 【建站知识】查询nginx日志状态码大于400的请求并打印整行04-03
- 【建站知识】Python中的logger和handler到底是个什么?04-03
- 【建站知识】python3拉勾网爬虫之(您操作太频繁,请稍后访问)04-03
- 【建站知识】xpath 获取meta里的keywords及description的方法04-03
- 【建站知识】python向上取整以50为界04-03
- 【建站知识】scrapy xpath遇见乱码解决04-03
- 【建站知识】scrapy爬取后中文乱码,解决word转为html 时cp1252编码问题04-03
- 【建站知识】scrapy采集—爬取中文乱码,gb2312转为utf-804-03