php-fpm慢日志slowlog设置可以让我们很好的看见哪些php进程速度太慢而导致的网站问题。
可以让我们方便的找到问题的所在。
代码如下
1
vi /data1/server/php-cgi/etc/php-fpm.conf
2
; The log file for slow requests
; Default Value: not set
; Note: slowlog is mandatory if request_slowlog_timeout is set
slowlog = /data1/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 = 1s
必须同时设置request_slowlog_timeout 0s表示关闭,就是slowlog没有用
1s表示超过1秒的处理都会被记录。
看看具体执行慢到多少秒
代码如下
1
/data1/server/php-cgi/var/log/php-fpm.log
2
[19-Apr-2013 12:40:35] WARNING: [pool www] child 29514, script ‘/xx/www/adx/tx/tm.php’ (request: “GET /tx/tm.php”) executing too slow (1.034708 sec), logging
补充一下不同版本php下开启慢日志教程
PHP 5.3.3 之前版本设置如下:
代码如下
1
The timeout (in seconds) for serving a single request after which the worker process will be terminated
Should be used when 'max_execution_time' ini option does not stop script execution for some reason
'0s' means 'off'
10s
The timeout (in seconds) for serving of single request after which a php backtrace will be dumped to slow.log file
'0s' means 'off'
1s
The log file for slow requests
logs/slow.log
PHP 5.3.3 之后版本设置如下:
代码如下
1
; 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 = 1s
2
; The log file for slow requests
; Default Value: /usr/local/php/log/php-fpm.log.slow
slowlog = /usr/local/php/log/php-fpm.log.slow
3
; The timeout for serving a single request after which the worker process will
; be killed. This option should be used when the 'max_execution_time' ini option
; does not stop script execution for some reason. A value of '0' means 'off'.
; Available units: s(econds)(default), m(inutes), h(ours), or d(ays)
; Default Value: 0
request_terminate_timeout = 10s
注:request_terminate_timeout 将执行时间太长的进程直接终止
request_slowlog_timeout 将执行过慢的文件写入日志
以后即可根据慢执行日志 /usr/local/php/logs/slow.log 来优化程序文件了!