一,突发神精,来把它们三儿来比较
在网上看到好多文章说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无逻辑文件
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
$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来说,肯定不是很合理的。