啟用 php-fpm 的 slow log 日志,查看執(zhí)行時(shí)間過(guò)長(zhǎng)的php文件,并將執(zhí)行時(shí)間過(guò)長(zhǎng)的進(jìn)程直接終止掉!看看效果如何!

具體操作方法也簡(jiǎn)單,就修改一個(gè)文件,執(zhí)行命令:# vi /usr/local/php/etc/php-fpm.conf

PHP 5.3.3 之前版本設(shè)置如下:

      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 之后版本設(shè)置如下:

; 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  (對(duì)執(zhí)行時(shí)間超過(guò)1s的php腳本進(jìn)行日志記錄)

; 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 (開(kāi)啟慢執(zhí)行日志,日志目錄路徑一定要正確存在,否則會(huì)報(bào)錯(cuò))

; 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 (當(dāng)php腳本執(zhí)行時(shí)間超過(guò)30秒后終止該php腳本)

注:request_terminate_timeout 將執(zhí)行時(shí)間太長(zhǎng)的進(jìn)程直接終止

request_slowlog_timeout 將執(zhí)行過(guò)慢的文件寫(xiě)入日志

以后即可根據(jù)慢執(zhí)行日志 /usr/local/php/var/log/slow.log 來(lái)優(yōu)化程序文件了!

轉(zhuǎn)載請(qǐng)注明來(lái)源:善用php-fpm的慢執(zhí)行日志slow log分析PHP執(zhí)行效率和程序BUG

  哈爾濱品用軟件有限公司致力于為哈爾濱的中小企業(yè)制作大氣、美觀的優(yōu)秀網(wǎng)站,并且能夠搭建符合百度排名規(guī)范的網(wǎng)站基底,使您的網(wǎng)站無(wú)需額外費(fèi)用,即可穩(wěn)步提升排名至首頁(yè)。歡迎體驗(yàn)最佳的哈爾濱網(wǎng)站建設(shè)。