登录  /  注册

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

藏色散人
发布: 2019-11-12 14:20:16
转载
1886人浏览过

环境说明

root@ubuntu:/home/tb# cat /etc/issue
Ubuntu 16.04.2 LTS \n \l
root@ubuntu:/home/tb# php -v
PHP 7.0.15-0ubuntu0.16.04.4 (cli) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend 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 fpm
root      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 www
www-data  3686  1642  0 17:14 ?        00:00:03 php-fpm: pool www
www-data  3808  1642  0 17:43 ?        00:00:03 php-fpm: pool www
root      3930  2208  0 18:10 pts/0    00:00:00 grep --color=auto fpm
root@ubuntu:/home/tb#
登录后复制

php-fpm.conf的最后一行为

include=/etc/php/7.0/fpm/pool.d/*.conf
登录后复制

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

314 ; The log file for slow requests
315 ; Default Value: not set
316 ; Note: slowlog is mandatory if request_slowlog_timeout is set
317 ;slowlog = log/$pool.log.slow
318
319 ; The timeout for serving a single request after which a PHP backtrace will be
320 ; 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: 0
323 ;request_slowlog_timeout = 0
登录后复制

添加两行配置

slowlog=/var/log/php7.0/fpm/slow.log
request_slowlog_timeout=1s
登录后复制

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

service php7.0-fpm reload
登录后复制

查看log回显结果

[03-Jan-2018 18:48:53]  [pool www] pid 4934
script_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-2018 18:48:53]  [pool www] pid 4931
script_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
登录后复制

关于log的说明

[03-Jan-2018 18:48:53]  [pool www] pid 4931
登录后复制

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

script_filename = /usr/share/nginx/ testapp/index.php
登录后复制

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

[0x00007fb626213520] session_start() /usr/share/nginx/ testapp/app/models/user_model.php:11
登录后复制

这个第三行比较重要:是堆栈顶部信息(is the top of the stack trace),他说明指出了超出了阈值的当前执行的方法的函数调用是哪个,以及具体的文件及代码行数

剩下的其他部分就是 调用的顺序(从下往上,最终导致变慢超时的结果)

其他说明

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

[0x00007fb6262136f0] curl_exec() /usr/share/nginx/
登录后复制

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

相关推荐:《PHP教程

以上就是php-fpm7.0 慢查询设置及说明的详细内容,更多请关注php中文网其它相关文章!

智能AI问答
PHP中文网智能助手能迅速回答你的编程问题,提供实时的代码和解决方案,帮助你解决各种难题。不仅如此,它还能提供编程资源和学习指导,帮助你快速提升编程技能。无论你是初学者还是专业人士,AI智能助手都能成为你的可靠助手,助力你在编程领域取得更大的成就。
来源:segmentfault网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
作者最新文章
最新问题
关于CSS思维导图的课件在哪? 课件
凡人来自于2024-04-16 10:10:18
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2024 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号