Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm having a strange issue with nginx and PHP-FPM. I have a server set up to serve downloads for my website. It's not very beasty, it's only a Celeron G530 and 4GB of RAM, because of this, I'm running nginx for its low overhead. The server is typically transfering at 30-40Mbps constantly and the port is 100Mbps.

The problem is, when I'm requesting some PHP scripts from the server over HTTP the request often times out. I know the time limit in nginx is 60 seconds, and I've verified through the logs that it's hitting that time and closing the connection.

I also have Munin running on the server to monitor things, and while this is still over HTTP, on the same server and under the same conditions, it's very quick and snappy with a page load taking no longer than 150ms.

In my head it makes logical sense that the problem lies with PHP-FPM (as far as I know Munin uses Perl), but how can I check this? What can I do to drill down on the problem and see what the actual bottlenecks are?

If it is PHP-FPM, what can I do to perhaps speed things up? It's not taking up a lot of CPU or RAM, and it's set up to use a socket connection rather than a TCP one with nginx.

Thanks for any help.

share|improve this question
Debug your PHP scripts? – Michael Hampton Mar 20 '13 at 11:50
up vote 0 down vote accepted

You should add slow logging to your php-fpm config:

request_slowlog_timeout = 10
slowlog = /var/log/php-fpm/slow.$pool.log

That will log all requests that take longer than 10 seconds, so you can see what scripts are not being 'snappy'. It gives a full stack trace of where the code is at the moment when the slow logging time limit was reached.

Also you can set up the PHP-FPM status page. Add this to your PHP-FPM pool config:

pm.status_path = /www-status

And pass the requests through nginx to PHP-FPM

location ~ ^/(www-status)$ {
    fastcgi_pass   unix:%phpfpm.socket%/php-fpm-www.sock;

    # or IP address
    # fastcgi_pass;

    fastcgi_index index.php;
    fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;

    allow stats_collector.localdomain;
    allow watchdog.localdomain;
    deny all;

Then going to will give you a big print out of every php-fpm process like:

pool:                 www
process manager:      dynamic
start time:           18/Mar/2013:20:17:21 +1100
start since:          243
accepted conn:        3
listen queue:         0
max listen queue:     0
listen queue len:     0
idle processes:       3
active processes:     1
total processes:      4
max active processes: 1
max children reached: 0
slow requests:        0

pid:                  6233
state:                Idle
start time:           18/Mar/2013:20:17:21 +1100
start since:          243
requests:             1
request duration:     631
request method:       GET
request URI:          /www-status
content length:       0
user:                 -
script:               /documents/projects/intahwebz/intahwebz/basereality/www-status
last request cpu:     0.00
last request memory:  262144
share|improve this answer

when I'm requesting some PHP scripts from the server over HTTP the request often times out

That implies that it doesn't happen for all scripts - and for the affected scripts it only happens some of the time - hence the solution is to simply look at what's different at the times the scripts work compared with when they don't, and to compare the scripts which work against those which don't. Also, check your logs.

(you might want to add monitoring of the number of php-fpm processes and HTTP connections to munin if you don't already have that in place).

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.