1. 首页
  2. 编程语言

php-fpm慢查询日志

因为php引擎自己不带监控慢查询的功能,因此您如果选择的是php-fpm作为终端来调用php引擎,那么我们这里介绍php-fpm监控php处理请求的慢查询日志方法。

php-fpm配置选项:

“slowlog” –  logging scripts (not just their names, but their PHP backtraces too, using ptrace and similar things to read remote process’ execute_data) that are executed unusually slow;

request_slowlog_timeout mixed

The timeout for serving a single request after which a PHP backtrace will be dumped to the ‘slowlog’ file. A value of ‘0’ means ‘Off’. Available units: s(econds)(default), m(inutes), h(ours), or d(ays). Default value: 0.

重启上面2个选项后,我们重启systemctl restart php-fpm后,就可以正常记录慢查询日志了。

慢查询日志记录格式案例:

[root@localhost php-fpm]# tail -f /var/log/php-fpm/www-slow.log

[27-Mar-2020 19:19:18]  [pool www] pid 4596
script_filename = /var/www/html/info.php
[0x00007fd41ec5e318] sleep() /var/www/html/info.php:11

注意的问题:

注意1.如果是centos7,开启了selinux安全系统,那么需要该安全系统开启给php-fpm(也可能是apache待查)某个权限,否则记录失败。并在php-fpm错误日志报错。

报错如下。
[27-Mar-2020 19:16:30] ERROR: failed to ptrace(ATTACH) child 4598: Operation not permitted (1)
注意2:如果有超时的请求,那么error日志也会有warning的警告和3个notice的追踪提示。如果请求不超时,则不提示。

[27-Mar-2020 19:19:18] WARNING: [pool www] child 4596, script ‘/var/www/html/info.php’ (request: “GET /info.php”) executing too slow (1.058668 sec), logging
[27-Mar-2020 19:19:18] NOTICE: child 4596 stopped for tracing
[27-Mar-2020 19:19:18] NOTICE: about to trace 4596
[27-Mar-2020 19:19:18] NOTICE: finished trace of 4596

本文来自投稿,不代表程序员编程网立场,如若转载,请注明出处:http://www.cxybcw.com/189228.html

联系我们

13687733322

在线咨询:点击这里给我发消息

邮件:1877088071@qq.com

工作时间:周一至周五,9:30-18:30,节假日休息

QR code