我试图重现这个基准,它将 PHP 7 与 Wordpress 服务器上的旧版本进行比较:http: //talks.php.net/oz15#/wpbench
我的配置几乎相同,服务器有 i7、SSD、16GB RAM 和 debian。服务器软件是nginx。令人惊讶的是,我的结果与上面链接的结果有很大不同。
在我的测试围攻(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
- 否则: 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
你知道为什么 PHP 7 在我使用 Wordpress 的测试中要慢得多吗?
启用 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