这篇文章给大家介绍的内容是关于怎么启用php-fpm中慢日志配置?有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。
虽然通过nginx accesslog可以记录用户访问某个接口或者网页所消耗的时间,但是不能清晰地追踪到具体哪个位置或者说函数慢,所以通过php-fpm慢日志,slowlog设置可以让我们很好的看见哪些php进程速度太慢而导致的网站问题
php-fpm.conf的配置文件中有一个参数request_slowlog_timeout是这样描述的
; the timeout for serving a single request after which a php backtrace will be; dumped to the 'slowlog' file. a value of '0s' means 'off'.; available units: s(econds)(default), m(inutes), h(ours), or d(ays); default value: 0; request_slowlog_timeout = 0
当request_slowlog_timeout 设为一个具体秒时request_slowlog_timeout =1,表示如果哪个脚本执行时间大于1秒,会记录这个脚本到慢日志文件中
request_slowlog_timeout =0表示关闭慢日志输出。
慢日志文件位置默认在php的安装目录下的log文件夹中,可以通过修改slowlog = log/$pool.log.slow参数来指定。
; the log file for slow requests; default value: not set; note: slowlog is mandatory if request_slowlog_timeout is set; slowlog = log/$pool.log.slow
php-fpm慢日志的例子,慢日志会记录下进程号,脚本名称,具体哪个文件哪行代码的哪个函数执行时间过长。
[27-may-2016 13:20:37] notice: child 16683 stopped for tracing[27-may-2016 13:20:37] notice: about to trace 16683[27-may-2016 13:20:37] notice: finished trace of 16683[27-may-2016 13:20:37] warning: [pool www] child 16720, script '/data/webapps/test/public/index.php' (request: "post /index.php/test/test/") executing too slow (1.204894 sec), logging
request_slowlog_timeout 和 slowlog需要同时设置,开启request_slowlog_timeout的同时需要开启 slowlog,慢日志路径需要手动创建
具体开启php-fpm慢日志步骤:
cd /apps/phpvi /apps/php/etc/php-fpm.conf去掉request_slowlog_timeout 、slowlog的前缀分号';',设置request_slowlog_timeout =1;:wq保存退出创建慢日志目录mkdir -p /apps/php/etc/log重启php-fpmkillall php-fpm/apps/php/sbin/php-fpm
相关文章推荐:
php中构造方法和析构方法的代码实现
php中常用的函数以及全局变量的总结(推荐)
以上就是怎么启用php-fpm中慢日志配置?的详细内容。