• 注册
热门标签
↑ 收起导航

启用 php-fpm 的 slow log 日志

前段时间折腾了一下 分析Centos系统下LNMP频繁502 Bad Gateway问题,但仍有漏网之鱼导致网站偶尔的 502 Bad Gateway,今天再折腾一下,启用 php-fpm 的 slow log 日志,查看执行时间过长的php文件,并将执行时间过长的进程直接终止掉!看看效果如何!

具体操作方法也简单,就修改一个文件,执行命令:# vi /usr/local/php/etc/php-fpm.conf

PHP 5.3.3 之前版本设置如下:

      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'
      <value name="request_terminate_timeout">10s</value>
      The timeout (in seconds) for serving of single request after which a php backtrace will be dumped to slow.log file
      '0s' means 'off'
      <value name="request_slowlog_timeout">1s</value>
      The log file for slow requests
      <value name="slowlog">logs/slow.log</value>

PHP 5.3.3 之后版本设置如下:

; 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

; 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

; 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 来优化程序文件了!

版权声明:转载请注明来自杨俊伟博客,本文地址:http://yangjunwei.com/a/725.html
除非注明,杨俊伟博客文章均为原创,转载请注明出处和链接!
 

沙发木了,占个板凳也不错~ »

发表评论 



我还是想用邮箱注册

登录

忘记密码 ?

用第三方帐号快捷登录

已有账户?前往登录吧~

注册