Friday, October 24, 2014

PHP-FPM: Socket vs TCP/IP and sysctl tweaking on Nginx Server

ที่มา : https://rtcamp.com/tutorials/php/fpm-sysctl-tweaking/

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

No comments:

Post a Comment