NGINX + PHP FPM connect() failed (110: Connection timed out) while connecting to upstream

nginxPHPphp-fpm

We're running a fairly large site using nginx and PHP-FPM and we're getting a lot of errors as the site load is quite high. We're getting "connect() failed (110: Connection timed out) while connecting to upstream"…upstream: "fastcgi://127.0.0.1:9000"

Here's my config file for PHP-FPM.

PHP-FPM:

[www]
listen = 127.0.0.1:9000
listen.allowed_clients = 127.0.0.1
user = nginx
group = nginx
pm = dynamic
pm.max_children = 100
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 100

slowlog = /var/log/php-fpm/www-slow.log

php_admin_value[error_log] = /var/log/php-fpm/www-error.log
php_admin_flag[log_errors] = on

What's the recommended config/number of servers/children for a high traffic site?

We tried using Unix Sockets instead of TCP and got no noticeable improvements. Right now the errors are:
connect() to unix:/var/run/php-fcgi.sock failed (11: Resource temporarily unavailable) while connecting to upstream…upstream: "fastcgi://unix:/var/run/php-fcgi.sock:"…

Thanks,

Leonard

Best Answer

Use unix sockets, instead of TCP/IP. So, you'd do something like:

listen = /tmp/php.sock

If you don't want to do something like that, check your firewall rules. If you're using any sort of conntrack rules, you could easily be filling up the table for that. See if there's any log messages in dmesg about it. You shouldn't really be using conntrack on a high-load server, so disabling that is probably a good idea.

Also, check your ulimit settings. If the number of open files is set too low, you could run into issues.