0

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.

Joe
  • 17
  • 1
  • 4

2 Answers2

0

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).

symcbean
  • 21,009
  • 1
  • 31
  • 52
0

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)$ {
    include       %mysite.root.directory%/conf/fastcgi.conf;
    fastcgi_pass   unix:%phpfpm.socket%/php-fpm-www.sock;

    # or IP address
    # fastcgi_pass 127.0.0.1:9000;


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

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

Then going to yoursite.com/www-status?full 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
Danack
  • 1,216
  • 1
  • 16
  • 27