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不通 那么问题很可能就出现在这 尝试注释上述代码再次访问响应恢复正常
希望你参考该教程能帮助你更快找到问题所在并解决
猜你需要

豫ICP备2021026617号-1  豫公网安备:41172602000185   Copyright © 2021-2028 www.78moban.com/ All Rights Reserved

本站作品均来自互联网,转载目的在于传递更多信息,并不代表本站赞同其观点和对其真实性负责。如有侵犯您的版权,请联系 1565229909#qq.com(把#改成@),我们将立即处理。