当前位置: 首页 > 后端技术 > PHP

php-fpm7.0慢查询设置及说明

时间:2023-03-29 23:33:40 PHP

环境说明root@ubuntu:/home/tb#cat/etc/issueUbuntu16.04.2LTS\n\lroot@ubuntu:/home/tb#php-vPHP7.0.15-0ubuntu0.16.04.4(cli)(NTS)版权所有(c)1997-2017ThePHPGroupZendEnginev3.0.0,版权所有(c)1998-2017ZendTechnologieswithZendOPcachev7.0.15-0ubuntu0.16.04.4,Copyright(c)1999-2017,byZendTechnologies查看php-fpm配置路径root@ubuntu:/home/tb#ps-ef|grepfpmroot16421010:17?00:00:01php-fpm:主进程(/etc/php/7.0/fpm/php-fpm.conf)www-data36851642017:14?00:00:04php-fpm:池wwwwww-数据36861642017:14?00:00:03php-fpm:池wwwwww-数据38081642017:43?00:00:03php-fpm:poolwwwroot39302208018:10pts/000:00:00grep--color=autofpmroot@ubuntu:/home/tb#php-fpm.conf最后一行包括=/etc/php/7.0/fpm/pool.d/*.conf然后我们去修改www.conf,查看slowquery314的介绍;慢速请求的日志文件315;默认值:不是set316;注意:slowlog是必须的ory如果request_slowlog_timeout是set317;slowlog=log/$pool.log.slow318319;为单个请求提供服务的超时时间,之后PHP回溯将为320;转储到“slowlog”文件。值“0s”表示“关闭”.321;可用单位:s(秒)(默认)、m(分)、h(我们的)或d(ays)322;DefaultValue:0323;request_slowlog_timeout=0添加两行配置slowlog=/var/log/php7.0/fpm/slow.logrequest_slowlog_timeout=1s重启fpm,注意目录权限服务php7.0-fpm等一般问题reload查看日志回显结果[03-Jan-201818:48:53][poolwww]pid4934script_filename=/usr/share/nginx/testapp/index.php[0x00007fb626213520]session_start()/usr/share/nginx/testapp/app/models/user_model.php:11[0x00007fb6262134a0]__construct()/usr/share/nginx/ci_2.2.0/core/Loader.php:303[0x00007fb626213390]model()/usr/share/nginx/testapp/app/core/my_Controller.php:39[0x00007fb6262132e0]??__construct()/usr/share/nginx/testapp/app/controllers/home.php:8[0x00007fb626213270]__construct()/usr/share/nginx/ci_2.2.0/core/CodeIgniter.php:308[0x00007fb6262130e0][INCLUDE_OR_EVAL]()/usr/share/nginx/testapp/index.php:325[03-Jan-201818:48:53][poolwww]pid4931script_filename=/usr/share/nginx/testapp/index.php[0x00007fb626213520]session_start()/usr/share/nginx/testapp/app/models/user_model.php:11[0x00007fb6262134a0]__construct()/usr/share/nginx/ci_2.2.0/core/Loader.php:303[0x00007fb626213390]model()/usr/share/nginx/testapp/app/core/my_Controller.php:39[0x00007fb6262132e0]??__construct()/usr/share/nginx/testapp/app/controllers/home.php:8[0x00007fb626213270]__construct()/usr/share/nginx/ci_2.2.0/core/CodeIgniter.php:308[0x00007fb6262130e0][INCLUDE_OR_EVAL]()/usr/share/nginx/testapp/index.php:325Explanationonlog[03-Jan-201818:48:53][poolwww]pid4931这个没有解释,timeprocessidscript_filename=/usr/share/nginx/testapp/index.php执行脚本name,phpweb应用都是单入口的[0x00007fb626213520]session_start()/usr/share/nginx/testapp/app/models/user_model.php:11第三行更重要:它是栈顶信息(我s栈顶),表示当前执行的方法是哪个函数调用超过了阈值,以及具体的文件和代码行数,剩下的部分是调用的顺序(从bottomtotop,最终会导致变慢超时的结果)其他解释:如果发现第三行类似curl_exec(),例如:这一般是网络io占用的时间,如果它有必要请第三方,然后。忍受。[0x00007fb6262136f0]curl_exec()/usr/share/nginx/同样如果有mysql_query之类的也是由于参考链接php-fpm配置how-to-read-the-php-slow-request-log慢SQL查询引起的