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

前端之家收集整理的这篇文章主要介绍了nginx +php-cgi,apahce+php-cli,cgi的比较前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

一,突发神精,来把它们三儿来比较

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

1,Nginxphp-cgi说明

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

2,apache+php-cgi说明

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

3,apache+PHP-cli说明

没作任何限制

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

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,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.

三,测试文件二test1.PHP

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,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.

四,个人分析

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

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

2,针对逻辑复杂的文件

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

上面所做对比,不考虑11Nginx,配合10php-cgi是否合理,这个就Nginx来说,肯定不是很合理的。

原文链接:https://www.f2er.com/nginx/447367.html

猜你在找的Nginx相关文章