首页
学习
活动
专区
圈层
工具
发布

PHP 7性能
EN

Stack Overflow用户
提问于 2015-09-01 09:43:49
回答 2查看 7.5K关注 0票数 24

我尝试复制这个基准测试,它将PHP7与Wordpress服务器上的旧版本进行比较:http://talks.php.net/oz15#/wpbench

我的配置几乎是一样的,服务器有一个i7、SSD、16 an内存和debian。服务器软件是nginx。令人惊讶的是,我的结果与上面提到的结果大不相同。

在我的测试包围(https://www.joedog.org/siege-home/)中,输出如下:

For PHP7.0.0RC1:

代码语言:javascript
复制
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

For PHP5.6.12:

代码语言:javascript
复制
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的服务器上)。测量结果如下:

  • PHP7.0.0RC1\PHP5.5.28
  • 数学: 0.201 / 0.683
  • 字符串操作: 0.271 \ 0.77
  • 循环: 0.166 \x{e76f} 0.486
  • 如果是: 0.12 \ 0.295

我上传了两个phpinfo()文件,以防有帮助:

  • PHP7.0.0RC1:http://simsso.de/downloads/stackoverflow/php7.html
  • PHP5.6.12-0+deb8u1:http://simsso.de/downloads/stackoverflow/php5.html版本

你知道为什么PHP 7在我的Wordpress测试中会慢得多吗?

在启用opcache的情况下,7的速度实际上是PHP 5的两倍。谢谢您的提示!

我在随机填充的WordPress服务器上进行了以下测量。

围城现在为PHP7.0.0RC1输出以下内容

代码语言:javascript
复制
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 

PHP5.6.12

代码语言:javascript
复制
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
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-09-24 18:52:30

根据您发布的phpinfo的输出,PHP7没有启用opcache,而PHP5却启用了它,仅这一点就会产生巨大的差异。

票数 21
EN

Stack Overflow用户

发布于 2018-11-01 10:44:07

目前,我在CLI端有相同的惊人结果--.

我的一个老项目使用PHING构建。它在PHP5.3上运行,然后在PHP5.6上运行。我试着使用PHP 7,发现了一个巨大的不同。所以我决定计时脚本的执行。

FYI是一个真实的项目,在构建过程中处理了数千个文件。

使用PHP5.3.29构建:3分44秒。

构建使用PHP7.2.11: 11分41秒。

我注意到CLI没有激活opcache,下面是opcache的结果:

使用PHP7.2.11+opcache构建:12分钟18秒。

是的,更糟的

FYI:

代码语言:javascript
复制
$ php --info |grep opcache
opcache.blacklist_filename => no value => no value
opcache.consistency_checks => 0 => 0
opcache.dups_fix => Off => Off
opcache.enable => On => On
opcache.enable_cli => On => On
opcache.enable_file_override => Off => Off
opcache.error_log => no value => no value
opcache.file_cache => no value => no value
opcache.file_cache_consistency_checks => 1 => 1
opcache.file_cache_only => 0 => 0
opcache.file_update_protection => 2 => 2
opcache.force_restart_timeout => 180 => 180
opcache.huge_code_pages => Off => Off
opcache.inherited_hack => On => On
opcache.interned_strings_buffer => 8 => 8
opcache.lockfile_path => /tmp => /tmp
opcache.log_verbosity_level => 1 => 1
opcache.max_accelerated_files => 10000 => 10000
opcache.max_file_size => 0 => 0
opcache.max_wasted_percentage => 5 => 5
opcache.memory_consumption => 128 => 128
opcache.opt_debug_level => 0 => 0
opcache.optimization_level => 0x7FFFBFFF => 0x7FFFBFFF
opcache.preferred_memory_model => no value => no value
opcache.protect_memory => 0 => 0
opcache.restrict_api => no value => no value
opcache.revalidate_freq => 2 => 2
opcache.revalidate_path => Off => Off
opcache.save_comments => 1 => 1
opcache.use_cwd => On => On
opcache.validate_permission => Off => Off
opcache.validate_root => Off => Off
opcache.validate_timestamps => On => On

顺便说一句,当从PHP 5切换到PHP 7时,我从来没有注意到apache在prod上有很大的不同。

可以说,对于这个项目,我将坚持PHP 5版本。

票数 -2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32328373

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档