PHP-FPM: Socket vs TCP/IP

0

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 = 127.0.0.1:9000

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

fastcgi_pass 127.0.0.1:9000;

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

service php5-fpm reload && service nginx reload