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

关于php-fpm7.0慢查询设置及说明,第1张

概述关于php-fpm7.0慢查询设置及说明 本篇文章给大家介绍PHP-fpm7.0 慢查询设置及说明,有一定的参考价值,需要的朋友可以参考一下,希望对大家有所帮助。

推荐学习:《PHP视频教程》

环境说明
root@ubuntu:/home/tb# cat /etc/issueUbuntu 16.04.2 LTS \n \lroot@ubuntu:/home/tb# PHP -vPHP 7.0.15-0ubuntu0.16.04.4 (cli) ( NTS )copyright (c) 1997-2017 The PHP GroupZend Engine v3.0.0, copyright (c) 1998-2017 Zend TechnologIEs    with Zend OPcache v7.0.15-0ubuntu0.16.04.4, copyright (c) 1999-2017, by Zend TechnologIEs
查看PHP-fpm配置路径
root@ubuntu:/home/tb# ps -ef |grep fpmroot      1642     1  0 10:17 ?        00:00:01 PHP-fpm: master process (/etc/PHP/7.0/fpm/PHP-fpm.conf)www-data  3685  1642  0 17:14 ?        00:00:04 PHP-fpm: pool wwwwww-data  3686  1642  0 17:14 ?        00:00:03 PHP-fpm: pool wwwwww-data  3808  1642  0 17:43 ?        00:00:03 PHP-fpm: pool wwwroot      3930  2208  0 18:10 pts/0    00:00:00 grep --color=auto fpmroot@ubuntu:/home/tb#

PHP-fpm.conf的最后一行为

include=/etc/PHP/7.0/fpm/pool.d/*.conf

那我们去那里改www.conf,查看关于慢查询的介绍

314 ; The log file for slow requests315 ; Default Value: not set316 ; Note: slowlog is mandatory if request_slowlog_timeout is set317 ;slowlog = log/$pool.log.slow318319 ; The timeout for serving a single request after which a PHP backtrace will be320 ; dumped to the 'slowlog' file. A value of '0s' means 'off'.321 ; Available units: s(econds)(default), m(inutes), h(ours), or d(ays)322 ; Default Value: 0323 ;request_slowlog_timeout = 0
添加两行配置
slowlog=/var/log/PHP7.0/fpm/slow.logrequest_slowlog_timeout=1s

重启fpm,同时注意目录权限等一般问题

service PHP7.0-fpm reload
查看log回显结果
[03-Jan-2018 18:48:53]  [pool www] pID 4934script_filename = /usr/share/@R_419_5603@/ testapp/index.PHP[0x00007fb626213520] session_start() /usr/share/@R_419_5603@/ testapp/app/models/user_model.PHP:11[0x00007fb6262134a0] __construct() /usr/share/@R_419_5603@/ci_2.2.0/core/Loader.PHP:303[0x00007fb626213390] model() /usr/share/@R_419_5603@/ testapp/app/core/my_Controller.PHP:39[0x00007fb6262132e0] __construct() /usr/share/@R_419_5603@/ testapp/app/controllers/home.PHP:8[0x00007fb626213270] __construct() /usr/share/@R_419_5603@/ci_2.2.0/core/CodeIgniter.PHP:308[0x00007fb6262130e0] [INCLUDE_OR_EVAL]() /usr/share/@R_419_5603@/ testapp/index.PHP:325[03-Jan-2018 18:48:53]  [pool www] pID 4931script_filename = /usr/share/@R_419_5603@/ testapp/index.PHP[0x00007fb626213520] session_start() /usr/share/@R_419_5603@/ testapp/app/models/user_model.PHP:11[0x00007fb6262134a0] __construct() /usr/share/@R_419_5603@/ci_2.2.0/core/Loader.PHP:303[0x00007fb626213390] model() /usr/share/@R_419_5603@/ testapp/app/core/my_Controller.PHP:39[0x00007fb6262132e0] __construct() /usr/share/@R_419_5603@/ testapp/app/controllers/home.PHP:8[0x00007fb626213270] __construct() /usr/share/@R_419_5603@/ci_2.2.0/core/CodeIgniter.PHP:308[0x00007fb6262130e0] [INCLUDE_OR_EVAL]() /usr/share/@R_419_5603@/ testapp/index.PHP:325
关于log的说明
[03-Jan-2018 18:48:53]  [pool www] pID 4931

这个没啥解释,时间进程ID

script_filename = /usr/share/@R_419_5603@/ testapp/index.PHP

执行脚本名称,PHP web应用都为单入口

[0x00007fb626213520] session_start() /usr/share/@R_419_5603@/ testapp/app/models/user_model.PHP:11

这个第三行比较重要:是堆栈顶部信息(is the top of the stack trace),他说明指出了超出了阈值的当前执行的方法的函数调用是哪个,以及具体的文件及代码行数
剩下的其他部分就是 调用的顺序(从下往上,最终导致变慢超时的结果)

其他说明

如果发现第三行是以类似curl_exec(),比如:这一般是网络io占用了时间,如果是必须请求第三方,那么。。忍吧。

[0x00007fb6262136f0] curl_exec() /usr/share/@R_419_5603@/

同样,如果有MysqL_query之类的,也是由于sql 慢查询导致的

参考链接

PHP-fpm配置:https://www.PHP.net/manual/zh/install.fpm.configuration.PHP

how-to-read-the-PHP-slow-request-log:https://serverpilot.io/docs/how-to-read-the-PHP-slow-request-log/

总结

以上是内存溢出为你收集整理的关于php-fpm7.0慢查询设置及说明全部内容,希望文章能够帮你解决关于php-fpm7.0慢查询设置及说明所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1159841.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-01
下一篇 2022-06-01

发表评论

登录后才能评论

评论列表(0条)

保存