Troubleshooting Slow Loading Pages in PHP-FPM

A very useful tool that you can use when troubleshooting slow loading pages in php-fpm is the slow log.
I recently had to troubleshoot a web application that became unresponsive. The server was running a PHP application, under PHP-FPM, Nginx and Varnish.
That was a lot of configuration files to go over and the the nginx logs were not very helpful. Setting the php-fpm slow log allowed me to see exactly where the problem was. In that specific case, a curl request to an external service.

The “slow” log

A neat feature of the php-fpm service, is the slow log that allows you to track slow loading php scripts.
If you look under /etc/php5/fpm/pool.d/www.conf , you will see an entry named request_slowlog_timeout.
You can set the value in seconds, minutes, hours or day, and if a single request will take longer that, it will show in the slow log.

For example, if you have a web page that takes over 30 seconds to load, you can set it to:
request_slowlog_timeout = 25s

Every request that takes over 25s on that page, will be shown in the log file.
[16-Mar-2014 10:04:22] [pool www] pid 2744
script_filename = /var/www/api/index.php
[0x0000f4600dac2480] curl_exec() /var/www/api/proxy.php:15

As you can see, this is pretty specific.
In my case, the problem was a curl_exec() call that was taking too long.

, , , , , , , , , , , , , , , , ,

Powered by WordPress. Designed by Woo Themes