System Admin

PHP-FPM: Socket vs TCP/IP

Tweaking FPM config

You may also need to tweak PHP-FPM config to match new sysctl.conf settings.

Open PHP-FPM pool config file:

vim /etc/php5/fpm/pool.d/www.conf

Look for line:

;listen.backlog = 128

Change it to:

listen.backlog = 65536

Restart php5-fpm service.

service php5-fpm restart

Using TCP/IP for FPM

Sockets are slightly faster as compared to TCP/IP connection. But they are less scalable by default.

If you start getting errors like below (as faced ovidiu here)

connect() to unix:/var/run/php5-fpm.sock failed or **apr_socket_recv: Connection reset by peer (104)**

Then it means you need to either switch to TCP/IP or tweak with linux-system parameter so that your OS can handle large number of connections.

Open PHP-FPM pool config file

vim /etc/php5/fpm/pool.d/www.conf

Replace line:

listen = /var/run/php5-fpm.sock

by line:

listen =

Changes to Nginx

Next, open Nginx virtual-host config file(s).

Look for line

fastcgi_pass unix:/var/run/php5-fpm.sock;

Replace it with


Important: Reload php-fpm and nginx so that changes can take effect.

service php5-fpm reload && service nginx reload

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *