首页 > php教程 > php手册 > 正文

Windows下 nginx+php快速配置及性能测试

php中文网
发布: 2016-06-06 19:59:31
原创
1728人浏览过

一、Windowsnginxphp环境配置: 1.下载php-5.3.16-nts-Win32-VC9-x86.zip(nts-非线程安全,nginx需要php的cgi模式运行),解压缩至d:\wnmp\php5 2.配置php.ini(可以将php.ini-development复制成php.ni,然后主要是4个位置配置): extension_dir = D:/wnmp/p

一、Windows+nginx+php环境配置:

1.下载php-5.3.16-nts-win32-vc9-x86.zip(nts-非线程安全,nginx需要php的cgi模式运行),解压缩至d:\wnmp\php5

2.配置php.ini(可以将php.ini-development复制成php.ni,然后主要是4个位置配置):

立即学习PHP免费学习笔记(深入)”;

extension_dir = "D:/wnmp/php5/ext"
登录后复制

extension=php_mysql.dll
...
登录后复制

cgi.fix_pathinfo=1
登录后复制

doc_root ="D:/wnmp/wwwroot"
登录后复制

3.下载nginx-1.3.4.zip Windows版,解压至d:\wnmp\nginx

4.配置nginx.conf,主要是站点目录和启用php:

立即学习PHP免费学习笔记(深入)”;

location / {
            root   D:/wnmp/wwwroot; #站点根目录
            index  index.html index.htm;
        }
登录后复制

# 去掉注释,指明目录
location ~ \.php$ {
            root           D:/wnmp/wwwroot;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
            include        fastcgi_params;
        }
登录后复制

配置就这么简单。


二、运行

1.运行php:

@echooff
echo Starting php...
php5\php-cgi.exe -b 127.0.0.1:9000 -c D:/wnmp/php5/php.ini
登录后复制

2.运行nginx:
@echooff
echo Starting nginx
nginx.exe -p D:/wnmp/nginx
登录后复制

3.停止php和nginx:
@echooff
echo Stopping nginx...  
taskkill /F /IM nginx.exe > nul
echo Stopping PHP FastCGI...
taskkill /F /IM php-cgi.exe > nul
pause
exit
登录后复制

三、性能测试

apache是xampp包,可能有些优化,nginx纯粹按上面的手工配置,感觉php-cgi不稳定

Pandora Avatars
Pandora Avatars

可以制作100多种独特风格的头像

Pandora Avatars 102
查看详情 Pandora Avatars

1.html测试:

立即学习PHP免费学习笔记(深入)”;

ab -n 200000 -c 20 -k http://localhost/test/index.htm
登录后复制

apache,7945.38个请求每秒.

立即学习PHP免费学习笔记(深入)”;

D:\xampp\apache\bin>ab -n 200000 -c 20 -k http://localhost/test/index.htm
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking localhost (be patient)
Completed 20000 requests
Completed 40000 requests
Completed 60000 requests
Completed 80000 requests
Completed 100000 requests
Completed 120000 requests
Completed 140000 requests
Completed 160000 requests
Completed 180000 requests
Completed 200000 requests
Finished 200000 requests


Server Software:        Apache/2.2.21
Server Hostname:        localhost
Server Port:            80

Document Path:          /test/index.htm
Document Length:        42354 bytes

Concurrency Level:      20
Time taken for tests:   25.172 seconds
Complete requests:      200000
Failed requests:        0
Write errors:           0
Keep-Alive requests:    198031
Total transferred:      8544538023 bytes
HTML transferred:       8471021747 bytes
Requests per second:    7945.38 [#/sec] (mean)
Time per request:       2.517 [ms] (mean)
Time per request:       0.126 [ms] (mean, across all concurrent requests)
Transfer rate:          331492.01 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.2      0      16
Processing:     0    3   5.8      0      31
Waiting:        0    2   5.0      0      31
Total:          0    3   5.8      0      31

Percentage of the requests served within a certain time (ms)
  50%      0
  66%      0
  75%      0
  80%      0
  90%     16
  95%     16
  98%     16
  99%     16
 100%     31 (longest request)
登录后复制

nginx,6986个请求每秒

立即学习PHP免费学习笔记(深入)”;

D:\xampp\apache\bin>ab -n 200000 -c 20 -k http://localhost:8080/index.htm
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking localhost (be patient)
Completed 20000 requests
Completed 40000 requests
Completed 60000 requests
Completed 80000 requests
Completed 100000 requests
Completed 120000 requests
Completed 140000 requests
Completed 160000 requests
Completed 180000 requests
Completed 200000 requests
Finished 200000 requests


Server Software:        nginx/1.3.4
Server Hostname:        localhost
Server Port:            8080

Document Path:          /index.htm
Document Length:        42354 bytes

Concurrency Level:      20
Time taken for tests:   28.641 seconds
Complete requests:      200000
Failed requests:        0
Write errors:           0
Keep-Alive requests:    198012
Total transferred:      8519030702 bytes
HTML transferred:       8471038962 bytes
Requests per second:    6983.09 [#/sec] (mean)
Time per request:       2.864 [ms] (mean)
Time per request:       0.143 [ms] (mean, across all concurrent requests)
Transfer rate:          290474.31 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.1      0      16
Processing:     0    3   6.1      0      47
Waiting:        0    2   4.8      0      31
Total:          0    3   6.1      0      47

Percentage of the requests served within a certain time (ms)
  50%      0
  66%      0
  75%      0
  80%      0
  90%     16
  95%     16
  98%     16
  99%     16
 100%     47 (longest request)
登录后复制

2.php测试

ngnix下的php-cgi直接奔溃,apache大概600个请求每秒。

怎么感觉还是apache好啊!?配置上有问题?

相关标签:
数码产品性能查询
数码产品性能查询

该软件包括了市面上所有手机CPU,手机跑分情况,电脑CPU,电脑产品信息等等,方便需要大家查阅数码产品最新情况,了解产品特性,能够进行对比选择最具性价比的商品。

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号