php开启慢日志

时间:2021-10-28 20:12:44

默认是以本机的安装路径

cd /usr/local/php/etc/

vim php-fpm.conf

; 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 //可以修改慢日志的路径 ; 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 = 1 //慢日志超时的时间

不过目录需要手动创建,不然重启php-fpm将会出错

mkdir /usr/local/php/log

php-fpm慢日志的例子,慢日志会记录下进程号,脚本名称,具体哪个文件哪行代码的哪个函数执行时间过长。

查看慢日志文件  tail -10f  pool.log.show

[19-Sep-2014 11:34:12]  [pool www] pid 2957
script_filename = /data/wwwroot/cms.91.com/webroot/mobile91.php
[0x00000000030c6c10] request_by_curl() /data/wwwroot/cms.91.com/webroot/mobile91.php:207
[0x00000000030c6190] request_by_curl() /data/wwwroot/cms.91.com/webroot/mobile91.php:189 [19-Sep-2014 11:34:47] [pool www] pid 2968
script_filename = /data/wwwroot/cms.91.com/webroot/mobile91.php
[0x000000000300b840] request_by_curl() /data/wwwroot/cms.91.com/webroot/mobile91.php:206
[0x000000000300adc0] request_by_curl() /data/wwwroot/cms.91.com/webroot/mobile91.php:189