nginx 配置unix socket,PHP配置unix socket

nginx 和 php-fpm 使用unix socket配置比原来的fastcgi_pass  127.0.0.1:9000速度快一倍

测试环境是单核2GB内存的机器,请求数量10000次,并发100 PHP脚本直接输出hello world平均测试QPS是5000/S左右

创建/tmp/php-fpm.sock文件

touch /tmp/php-fpm.sock

chmod  0777 /tmp/php-fpm.sock  给文件权限

PHP配置unix socket:

cd /usr/local/php/etc/php-fpm.d

vim  www.conf (我的配置文件是www.conf)

;listen = 127.0.0.1:9000  (默认是这样的)
listen = /tmp/php-fpm.sock

然后启动PHP /usr/local/php/sbin/php-fpm  -c /usr/local/php/etc/php.ini

 

nginx配置unix socket:

在nginx的配置文件server段

location ~ .php(.*)$ {
            root /usr/local/nginx/html/xxx;
            #fastcgi_pass 127.0.0.1:9000;
            fastcgi_pass unix:/tmp/php-fpm.sock;
            fastcgi_index index.php;
            fastcgi_split_path_info ^(.+.php)(.*)$;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_param PATH_INFO $fastcgi_path_info;
            fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
            include fastcgi_params;
}

重启nginx

测压:ab -n 10000 -c 1000  http://localhost/hello.php

Server Software:        nginx
Server Hostname:        localhost
Server Port:            80

Document Path:          /hello.php
Document Length:        11 bytes

Concurrency Level:      1000
Time taken for tests:   1.932 seconds
Complete requests:      10000
Failed requests:        2204
   (Connect: 0, Receive: 0, Length: 2204, Exceptions: 0)
Write errors:           0
Non-2xx responses:      2204
Total transferred:      1963988 bytes
HTML transferred:       451620 bytes
Requests per second:    5175.22 [#/sec] (mean)
Time per request:       193.228 [ms] (mean)
Time per request:       0.193 [ms] (mean, across all concurrent requests)
Transfer rate:          992.58 [Kbytes/sec] received

 

之前用 fastcgi_pass 127.0.0.1:9000  TCP协议跟nginx通讯的情况,QPS只有2500这样,单机的情况下强烈推荐用unix socket 跟nginx通讯,如果php在其他机器上,那只能走ip端口的TCP协议了。

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值