nginx +php-cgi,apahce+php-cli,cgi的比较

jackxiang 2010-9-27 17:00 | |
一,突发神精,来把它们三儿来比较

在网上看到好多文章说nginx有多么,多么好。不管好不好,看看测试结果在说,

1,nginx+php-cgi说明

nginx我开启了11个进程,php-cgi我开启了10个进程

2,apache+php-cgi说明

httpd我开启了11个进程,php-cgi我开启了10个进程

3,apache+php-cli说明

没作任何限制

二,测试文件一test.php无逻辑文件

   1. <?php  
   2. phpinfo();  
   3. ?>  

<?php
phpinfo();
?>

1,nginx+php-cgi

[root@BlackGhost zhangy]# /usr/local/bin/webbench -c 100 -t 30 http://localhost/test.php
Webbench – Simple Web Benchmark 1.5
Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.

Benchmarking: GET http://localhost/test.php
100 clients, running 30 sec.

Speed=61598 pages/min, 1524550 bytes/sec.
Requests: 30799 susceed, 0 failed.

2,apache+php-cgi

[root@BlackGhost zhangy]# /usr/local/bin/webbench -c 100 -t 30 http://localhost/test.php
Webbench – Simple Web Benchmark 1.5
Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.

Benchmarking: GET http://localhost/test.php
100 clients, running 30 sec.

Speed=15000 pages/min, 371750 bytes/sec.
Requests: 7500 susceed, 0 failed.

3,apache+php-cli

[root@BlackGhost conf]# /usr/local/bin/webbench -c 100 -t 30 http://localhost/test.php
Webbench – Simple Web Benchmark 1.5
Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.

Benchmarking: GET http://localhost/test.php
100 clients, running 30 sec.

Speed=54618 pages/min, 1357257 bytes/sec.
Requests: 27309 susceed, 0 failed.

三,测试文件二test1.php
查看复制打印?

   1. <?php  
   2. $con = mysql_connect("localhost","username","password");  
   3. if (!$con)  
   4.   {  
   5.   die('Could not connect: ' . mysql_error());  
   6.   }  
   7.  
   8. mysql_select_db("test", $con);  
   9. mysql_query('set names utf8');  
  10.  
  11. $result = mysql_query("SELECT id, name, sex FROM test ");  
  12.  
  13. while($row = mysql_fetch_array($result))  
  14.   {  
  15.   echo $row['id'] . "+" . $row['name']."+".$row['sex'];  
  16.   echo "
  17. ";  
  18.   }  
  19.  
  20. mysql_close($con);  
  21. ?>  

<?php
$con = mysql_connect("localhost","username","password");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("test", $con);
mysql_query('set names utf8');

$result = mysql_query("SELECT id, name, sex FROM test ");

while($row = mysql_fetch_array($result))
  {
  echo $row['id'] . "+" . $row['name']."+".$row['sex'];
  echo "
";
  }

mysql_close($con);
?>

1,nginx+php-cgi

[root@BlackGhost zhangy]# /usr/local/bin/webbench -c 100 -t 30 http://localhost/test1.php
Webbench – Simple Web Benchmark 1.5
Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.

Benchmarking: GET http://localhost/test1.php
100 clients, running 30 sec.

Speed=60716 pages/min, 324830 bytes/sec.
Requests: 30358 susceed, 0 failed.

2,apache+php-cgi

[root@BlackGhost zhangy]# /usr/local/bin/webbench -c 100 -t 30 http://localhost/test1.php
Webbench – Simple Web Benchmark 1.5
Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.

Benchmarking: GET http://localhost/test1.php
100 clients, running 30 sec.

Speed=12800 pages/min, 68906 bytes/sec.
Requests: 6400 susceed, 0 failed.

3,apache+php-cli

[root@BlackGhost zhangy]# /usr/local/bin/webbench -c 100 -t 30 http://localhost/test1.php
Webbench – Simple Web Benchmark 1.5
Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.

Benchmarking: GET http://localhost/test1.php
100 clients, running 30 sec.

Speed=78844 pages/min, 575834 bytes/sec.
Requests: 39422 susceed, 0 failed.

四,个人分析

1,针对无逻辑文件,或者静态文件

在内存,cpu都没有最大化利用的情况下nginx+php-cgi效果比apache+php-cli的效果好一点,而apache+php- cli是最大化用内存和cpu,由起可见,nginx+php-cgi的对无罗辑或静态文件的解析要好很多。apache+php-cgi的效果很差,虽然php官方力挺php-cgi,但是根apache的配合效果不好。

2,针对逻辑复杂的文件

针对逻辑复杂的文件时,nginx+php-cgi对php的解析的效果下降了,但是下降的不是很厉害。而apache+php-cli对php的解析的效果去增强了,增加了很多,是原来的差不多1.5倍。nginx+php-cgi在利用部分内存和CPU的情况下根apache+php-cli对 php的解析都差不了多少,个人认为。nginx+php-cgi要比apache+php-cli要好。但是要想达到好多好多倍,我看难。

上面所做对比,不考虑11nginx,配合10php-cgi是否合理,这个就nginx来说,肯定不是很合理的。
来源:http://blog.51yip.com/apachenginx/619.html

作者:jackxiang@向东博客 专注WEB应用 构架之美 --- 构架之美,在于尽态极妍 | 应用之美,在于药到病除
地址:http://jackxiang.com/post/3542/
版权所有。转载时必须以链接形式注明作者和原始出处及本声明!

评论列表
发表评论

昵称

网址

电邮

打开HTML 打开UBB 打开表情 隐藏 记住我 [登入] [注册]