我尝试复现了这个基准测试,它比较了在一个WordPress服务器上使用PHP 7和旧版本的性能:http://talks.php.net/oz15#/wpbench
我的配置几乎相同,服务器配备了i7处理器,固态硬盘,16GB内存和debian操作系统。服务器软件是nginx。令人惊讶的是,我的测试结果与上面链接的结果有很大不同。
在我的测试中,Siege (https://www.joedog.org/siege-home/) 输出如下:
对于 PHP 7.0.0RC1:
siege -c100 -r100 http://10.22.255.133/wordpress/
** SIEGE 3.0.8
** Preparing 100 concurrent users for battle.
The server is now under siege.. done.
Transactions: 10000 hits
Availability: 100.00 %
Elapsed time: 131.61 secs
Data transferred: 95.77 MB
Response time: 0.75 secs
Transaction rate: 75.98 trans/sec
Throughput: 0.73 MB/sec
Concurrency: 56.98
Successful transactions: 10000
Failed transactions: 0
Longest transaction: 1.01
Shortest transaction: 0.04
对于 PHP 5.6.12 版本:
siege -c100 -r100 http://10.22.255.133/wordpress/
** SIEGE 3.0.8
** Preparing 100 concurrent users for battle.
The server is now under siege.. done.
Transactions: 10000 hits
Availability: 100.00 %
Elapsed time: 63.41 secs
Data transferred: 95.77 MB
Response time: 0.03 secs
Transaction rate: 157.70 trans/sec
Throughput: 1.51 MB/sec
Concurrency: 4.45
Successful transactions: 10000
Failed transactions: 0
Longest transaction: 0.63
Shortest transaction: 0.01
观察交易速率,可以看出PHP 5大约比PHP 7快两倍。我不敢相信。
另一个有趣的事实是,在运行此基准测试(http://www.php-benchmark-script.com/)时,PHP 7的结果约为PHP 5的3倍(当然在同一台服务器上,我也测试了WordPress)。 测量结果如下:
- PHP 7.0.0RC1 | PHP 5.5.28
- 数学: 0.201 | 0.683
- 字符串操作: 0.271 | 0.77
- 循环: 0.166 | 0.486
- If Else: 0.12 | 0.295
如果需要帮助,我已上传了phpinfo()文件:
- PHP版本7.0.0RC1:http://simsso.de/downloads/stackoverflow/php7.html
- PHP版本5.6.12-0+deb8u1:http://simsso.de/downloads/stackoverflow/php5.html
你有任何想法吗?为什么我的WordPress测试中PHP 7要慢那么多?
启用opcache后,PHP 7实际上比PHP 5快两倍。感谢Mjh的提示!
我对一个随机填充的WordPress服务器进行了以下测量。
现在Siege对PHP 7.0.0RC1输出如下:
Transactions: 10000 hits
Availability: 100.00 %
Elapsed time: 62.14 secs
Data transferred: 604.20 MB
Response time: 0.02 secs
Transaction rate: 160.93 trans/sec
Throughput: 9.72 MB/sec
Concurrency: 3.77
Successful transactions: 10000
Failed transactions: 0
Longest transaction: 0.41
Shortest transaction: 0.01
还有PHP 5.6.12:
siege -c100 -r100 http://10.22.255.133/wordpress/
** SIEGE 3.0.8
** Preparing 100 concurrent users for battle.
The server is now under siege.. done.
Transactions: 10000 hits
Availability: 100.00 %
Elapsed time: 119.98 secs
Data transferred: 604.20 MB
Response time: 0.60 secs
Transaction rate: 83.35 trans/sec
Throughput: 5.04 MB/sec
Concurrency: 49.86
Successful transactions: 10000
Failed transactions: 0
Longest transaction: 4.06
Shortest transaction: 0.04
siege
? - Mjhphp-fpm
的配置在两个 PHP 版本中是否相同?此外,似乎您的 PHP 7 没有启用 Opcache,而 PHP 5 则已启用。这可能会导致巨大的差异。 - Mjh