一,突发神精,来把它们三儿来比较
在网上看到好多文章说Nginx有多么,多么好。不管好不好,看看测试结果在说,
Nginx我开启了11个进程,php-cgi我开启了10个进程
2,apache+php-cgi说明
httpd我开启了11个进程,php-cgi我开启了10个进程
3,apache+PHP-cli说明
没作任何限制
PHP PHPinfo(); ?>
[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,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,running 30 sec.
Speed=54618 pages/min,1357257 bytes/sec.
Requests: 27309 susceed,0 Failed.
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); ?>
[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,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,running 30 sec.
Speed=78844 pages/min,575834 bytes/sec.
Requests: 39422 susceed,0 Failed.
四,个人分析
在内存,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要好。但是要想达到好多好多倍,我看难。
原文链接:https://www.f2er.com/nginx/447367.html