Nginx – Identify Long Running or Slow PHP Scripts

nginxperformancephp-fpmphp5web-server

I have web server that is getting around 25K visits a day up at yougetsignal.com. Sometimes the site feels a bit sluggish. I am hosting it on nginx with php5-fpm. Is there a way for me to see a list of all of the long running requests that are coming to the site?

I'd love to have a real-time list of all of the active requests that PHP is handling and how long they have been running. Kind of like top, but just for the web server. This would let me know how long requests are taking and which script is the culprit.

Anyone have any ideas on how I can do this?

Best Answer

In your PHP-FPM configuration file, for the Pool Definitions, you can enable a "slow log" that can provide more information on long-running PHP scripts:

; 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 = 0

Uncomment slowlog and set to a valid file name, and uncomment request_slowlog_timeout and set to 10s or whatever value you think is too long, then reload/restart PHP-FPM.

Related Topic