nginx php fpm socket,php-fpm 使用 socket 方式和 nginx 通讯,(速度优化)
1、什么是域Socket
“Unix domain socket 或者 IPCsocket 是一種終端,可以使同一臺操作系統(tǒng)上的兩個或多個進程進行數(shù)據(jù)通信。與管道相比,Unix domain sockets 既可以使用字節(jié)流數(shù)和數(shù)據(jù)隊列,而管道通信則只能通過字節(jié)流。Unix domain sockets的接口和Internet socket很像,但它不使用網(wǎng)絡底層協(xié)議來通信。Unix domain socket 的功能是POSIX操作系統(tǒng)里的一種組件。 Unix domain sockets 使用系統(tǒng)文件的地址來作為自己的身份。它可以被系統(tǒng)進程引用。所以兩個進程可以同時打開一個Unix domain sockets來進行通信。不過這種通信方式是發(fā)生在系統(tǒng)內(nèi)核里而不會在網(wǎng)絡里傳播。”
nginx連接fastcgi的方式是http方式的,在linux還有一種速度更快的方法就是通過unix?domain?socket來完成,下面介紹這種方法:
php-fpm 使用 socket 方式和 nginx 通訊
建立 PHP-FPM 使用一個 Unix Socket
vi /etc/php-fpm.d/
[...]
;listen = 127.0.0.1:9000
listen = /tmp/php-fcgi.sock
[...]
重啟PHP-FPM
systemctl restart php-fpm.service
配置文件:
vi /etc/nginx/conf.d/default.conf
配置內(nèi)容如下:
[...]
location ~ \.php$ {
root /usr/share/nginx/html;
;fastcgi_pass 127.0.0.1:9000;
fastcgi_pass unix:/tmp/php-fcgi.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
[...]
重啟Nginx
#chmod 777 /tmp/php-fcgi.sock // 修改讀寫權(quán)限
總結(jié)
以上是生活随笔為你收集整理的nginx php fpm socket,php-fpm 使用 socket 方式和 nginx 通讯,(速度优化)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python创建函数、可以接受任意多个整
- 下一篇: php error docref,PHP