|
Q:基于什么樣的理由 PHP 比其它 CGI 好呢?有沒有比較具體的數(shù)據(jù)可以證明 PHP 執(zhí)行與其它 CGI 執(zhí)行的效率好 ? 現(xiàn)在我的公司是用 C 來寫 CGI 的,如果換成 PHP,會(huì)不會(huì)比較好呢 ?沒有強(qiáng)而有力的依據(jù)的話,我就沒辦法說服上面的人讓我轉(zhuǎn)成 PHP 了...
A: 我認(rèn)為"好" 要有三點(diǎn) 第一: 寫出來的程式的執(zhí)行速度快. 第二: 遇到有大量存取時(shí)的執(zhí)行效能強(qiáng). 第三: 程式開發(fā)的時(shí)間快,易維護(hù)。 php在這三點(diǎn)中,雖都不一定是最好的,但也都在前茅
以下是C,PHP和Perl在速度方面的比較 我用下面的算式測試 $s=1.0; for ($i=1;$i<=10;$i++) { for ($j=1;$j<=10;$j++) { $s=$s*1.0005; $s=$s/1.0004; }; }; print $s; ?> 然后用ab -n 10000 -c 20 http://mycgi 測試,結(jié)果 C語言用了 37.511 秒 PHP3用了 45.393 秒 PERL用了 68.418 秒
看起是C 最快沒錯(cuò),不過,和PHP3的結(jié)果沒有太大 的差距。 Perl最慢
以下為測試數(shù)據(jù) ============================================== C 語言 ==============================================
Document Path: /~evan/test/gcc.cgi Document Length: 19 bytes
Concurrency Level: 20 Time taken for tests: 37.511 seconds Complete requests: 10000 Failed requests: 0 Total transferred: 1750000 bytes HTML transferred: 190000 bytes Requests per second: 266.59 Transfer rate: 46.65 kb/s received
Connnection Times (ms) min avg max Connect: 0 30 3001 Processing: 4 40 69 Total: 4 70 3070
PHP3 ============================================== Document Path: /~evan/test/php3.php3 Document Length: 15 bytes
Concurrency Level: 20 Time taken for tests: 45.393 seconds Complete requests: 10000 Failed requests: 0 Total transferred: 1710000 bytes HTML transferred: 150000 bytes Requests per second: 220.30 Transfer rate: 37.67 kb/s received
Connnection Times (ms) min avg max Connect: 0 34 3039 Processing: 6 53 183 Total: 6 87 3222
PERL ============================================== Document Path: /~evan/test/perl.cgi Document Length: 17 bytes
Concurrency Level: 20 Time taken for tests: 68.418 seconds Complete requests: 10000 Failed requests: 0 Total transferred: 1730173 bytes HTML transferred: 170017 bytes Requests per second: 146.16 Transfer rate: 25.29 kb/s received
Connnection Times (ms) min avg max Connect: 0 22 3005 Processing: 9 112 323 Total: 9 134 3328
|