Php – How to debug nginx/php-fpm for site that hangs

drupalnginxPHP

I need some tips on how to debug a new server config that hangs. This site itself is a very big instance of Drupal. Big as in a 45+ MB of PHP memory per page load with APC functioning.

The site itself does run on another server with nginx/php-fpm/apc. The new server I'm setting up has a custom PHP 5.3 build.

nginx is configured to listen on port 80, and passes the fastcgi request to 127.0.0.1:9000. This works.

In the Drupal root directory, I have a plain PHP file with phpinfo(); in it. I can load this PHP file directly and confirm the PHP build looks good.

There is no nginx error, but the php-fpm error log will show this as the page hangs:

[22-Dec-2012 17:41:16] WARNING: [pool www] child 19760, script '/var/www/mysite/public_html/index.php' (request: "GET /index.php") executing too slow (5.068781 sec), logging

Besides this error, there's nothing.

So I'm looking for advice on ways to debug this considering a normal PHP script loads fine, but loading a Drupal app (directly to index.php, not even trying clean urls) hangs.

Best Answer

When you see that error log entry in your php-fpm error log, it's actually providing a helpful stack trace of the slow php process.

In your php-fpm configuration file (e.g. /etc/php-fpm.d/www.conf), take a look at the request_slowlog_timeout and slowlog settings. The first defines how many seconds until a request is considered "slow", and the latter defines the file that stack traces will be written to.

If you look at the php-fpm slowlog file, you'll get a better idea of exactly where in the method call stack your processes are hanging up at.