- 工信部備案號 滇ICP備05000110號-1
- 滇公安備案 滇53010302000111
- 增值電信業務經營許可證 B1.B2-20181647、滇B1.B2-20190004
- 云南互聯網協會理事單位
- 安全聯盟認證網站身份V標記
- 域名注冊服務機構許可:滇D3-20230001
- 代理域名注冊服務機構:新網數碼
Nginx連接fastcgi的方式有2種:unix domain socket和TCP,Unix domain socket 或者 IPC socket是一種終端,可以使同一臺操作系統上的兩個或多個進程進行數據通信。與管道相比,Unix domain sockets 既可以使用字節流和數據隊列,而管道通信則只能通過字節流。Unix domain sockets的接口和Internet socket很像,但它不使用網絡底層協議來通信。Unix domain socket 的功能是POSIX操作系統里的一種組件。
TCP和unix domain socket方式對比
TCP是使用TCP端口連接127.0.0.1:9000
Socket是使用unix domain socket連接套接字/dev/shm/php-cgi.sock(很多教程使用路徑/tmp,而路徑/dev/shm是個tmpfs,速度比磁盤快得多)
fastcgi_pass unix:/tmp/php-cgi.sock
fastcgi_pass 127.0.0.1:9000
在服務器壓力不大的情況下,tcp和socket差別不大,但在壓力比較滿的時候,用套接字方式,效果確實比較好。
下面是php 5.3以上版本將TCP改成socket方式的配置方法:
修改php-fpm.conf(/usr/local/php/etc/php-fpm.conf)
;listen = 127.0.0.1:9000
listen = /dev/shm/php-cgi.sock
修改nginx配置文件server段的配置,將http的方式改為socket方式
location ~ .*.(php|php5)?$
{
#fastcgi_pass 127.0.0.1:9000;
fastcgi_pass unix:/dev/shm/php-cgi.sock;
fastcgi_index index.php;
include fastcgi.conf;
}
重啟php-fpm與nginx
service nginx restart
service php-fpm restart
ls -al /dev/shm
可以看到php-cgi.sock文件unix套接字類型,理論上,unix socket 不走網絡,效率高一些,但穩定性不是很理想。
售前咨詢
售后咨詢
備案咨詢
二維碼
TOP