Let PHP-FPM report the script's current line number on timeout

i.amniels asked:

My website is running successfully on PHP-FPM with NGINX on Debian. Timeout period is set at 300 seconds for NGINX. This is enough for most pages, but some scripts get stuck. I can’t reproduce the issue in testing, so I would like to know where the script is stuck. Can PHP-FPM report the last line number when a time out occurs?

My answer:

You can enable the php-fpm slow log. If a request takes more than a configurable amount of time, php-fpm will dump a stack trace to a log file.

An example configuration, which goes into your php-fpm pool configuration file:

slowlog = /var/log/php5/slow.log
request_slowlog_timeout = 5s

In this case, any request that takes more than 5 seconds of wall clock time will get a stack dump into /var/log/php5/slow.log.

Note that the request will continue running.

View the full question and any other answers on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.