php-fpm TCP通訊改成unit socket通訊php
原理上來講,unix socket方式確定要比tcp的方式快並且消耗資源少,由於socket之間在nginx和php-fpm的進程之間通訊,而tcp須要通過本地迴環驅動,還要申請臨時端口和tcp相關資源,unix socket會顯得不是那麼穩定,當併發鏈接數爆發時,會產生大量的長時緩存,在沒有面向鏈接協議支撐的狀況下,大數據包頗有可能就直接出錯並不會返回異常。而TCP這樣的面向鏈接的協議,多少能夠保證通訊的正確性和完整性。nginx
touch /var/run/php-fcgi.sock chmod 777 /var/run/php-fcgi.sock chown nginx. /var/run/php-fcgi.sock
修改www.conf緩存
listen = /var/run/php-fcgi.sock listen.owner = nginx listen.group = nginx listen.mode = 0666 user = nginx group = nginx
修改nginx配置文件;cookie
# fastcgi_pass 127.0.0.1:9000; fastcgi_pass unix:/var/run/php-fcgi.sock;
修改sysctl.conf;session
# vi /etc/sysctl.conf net.ipv4.ip_local_port_range = 1024 65535 net.ipv4.tcp_syncookies = 1 net.ipv4.tcp_tw_reuse = 1 net.ipv4.tcp_tw_recycle = 1 net.ipv4.tcp_fin_timeout = 30 # sysctl –p
//上面參數是必須的,1是增長端口數量,2是減小time_wait鏈接過多 併發
先restart php-fpm
而後:nginx -s stop
Nginx
不能用restart,會出錯,解決步驟:socket
ps -aux | grep nginx | awk ‘{print $2}’| xargs kill -9
進行測試tcp
www.conf示例內容:ide
[www] ;listen = 127.0.0.1:9000 listen = /var/run/php-fcgi.sock listen.allowed_clients = 127.0.0.1 listen.owner = nginx listen.group = nginx listen.mode = 0666 pm = dynamic pm.max_children = 1000 pm.start_servers = 150 pm.min_spare_servers = 50 pm.max_spare_servers = 1000 pm.max_requests = 1000 slowlog = /var/log/php-fpm/www-slow.log php_value[session.save_handler] = files php_value[session.save_path] = /var/lib/php/session php_value[soap.wsdl_cache_dir] = /var/lib/php/wsdlcache