php专区

 首页 > php专区 > PHP高级 > 缓存异常处理 > 善用php-fpm的慢执行日志slowlog分析PHP执行效率和程序BUG

善用php-fpm的慢执行日志slowlog分析PHP执行效率和程序BUG

分享到:
【字体:

启用 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'
      request_terminate_timeout">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'
      request_slowlog_timeout">1s
      The log file for slow requests
      logs/slow.log

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  (对执行时间超过1s的php脚本进行日志记录)

; The log file for slow requests
; Default Value: /usr/local/php/var/log/php-fpm.log.slow
slowlog = /usr/local/php/var/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 = 30s (当php脚本执行时间超过30秒后终止该php脚本)

注:request_terminate_timeout 将执行时间太长的进程直接终止

request_slowlog_timeout 将执行过慢的文件写入日志

以后即可根据慢执行日志 /usr/local/php/var/log/slow.log 来优化程序文件了!

分享到:
PHP相关系列-安装php环境错误解决
错误: configure: error: libevent >= 1.4.11 could not be found  解决: yum -y install libevent libevent-devel 错误:configure: error: xml2-config not found. Please check your libxml2 installation.  解决: yum -y install libxml2 libxml2-devel 错误: configure: error: mcrypt.h not found. Please reinstal...
线上PHP问题排查思路与实践
前言 前几天,在一淘网,腾讯网媒和微博商业技术联合组织的技术分享大会上,我分享了《在线PHP问题排查思路与实践》。此博文除了对PPT提供下载外,还会对ppt做简单的注释说明。主题分为三部分,常见问题,解决思路和案例分析。 常见问题 不同用户看到的错误可能不一样。一般用户看到的错误都是表层的现象...
  •         php迷,一个php技术的分享社区,专属您自己的技术摘抄本、收藏夹。
  • 在这里……