这篇文章主要介绍了PHP7.2、PHP7.1 性能对比的示例分析,具有一定借鉴价值,需要的朋友可以参考下。希望大家阅读完这篇文章后大有收获。下面让小编带着大家一起了解一下。
成都创新互联是专业的南溪网站建设公司,南溪接单;提供成都网站制作、网站设计,网页设计,网站设计,建网站,PHP网站建设等专业做网站服务;采用PHP框架,可快速的进行南溪网站开发网页制作和功能扩展;专业做搜索引擎喜爱的网站,专业的做网站团队,希望更多企业前来合作!服务器配置
2核 Intel(R) Xeon(R) CPU E5-2640 0 @ 2.50GHz 内存 4G 系统 Centos 6.2 gcc 4.4.7
安装
# http://hk1.php.net/get/php-7.1.10.tar.gz/from/this/mirror $ ./configure --prefix=/data/local/php71 --with-config-file-path=/data/local/php71/etc --enable-fpm --with-fpm-user=www --with-fpm-group=www --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv-dir --with-freetype-dir=/usr/local/freetype --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --enable-intl --enable-pcntl --with-mcrypt --enable-ftp --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --with-gettext --disable-fileinfo --enable-opcache --with-xsl
# https://downloads.php.net/~remi/php-7.2.0RC3.tar.gz $ ./configure --prefix=/data/local/php72 --with-config-file-path=/data/local/php72/etc --enable-fpm --with-fpm-user=www --with-fpm-group=www --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv-dir --with-freetype-dir=/usr/local/freetype --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --enable-intl --enable-pcntl --enable-ftp --with-gd --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --with-gettext --disable-fileinfo --enable-opcache --with-xsl
$ /data/local/php71/bin/php -v PHP 7.1.10 (cli) (built: Oct 8 2017 16:08:01) ( NTS ) Copyright (c) 1997-2017 The PHP Group Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
$ /data/local/php72/bin/php -v PHP 7.2.0RC3 (cli) (built: Oct 8 2017 18:11:35) ( NTS ) Copyright (c) 1997-2017 The PHP Group Zend Engine v3.2.0-dev, Copyright (c) 1998-2017 Zend Technologies
php.ini 配置
仅供测试,非生产环境使用,摘录自 www.laruence.com/2016/12/18/…
engine = On short_open_tag = Off realpath_cache_size = 2M max_execution_time = 86400 memory_limit = 1024M error_reporting = 0 display_errors = 0 display_startup_errors = 0 log_errors = 0 default_charset = "UTF-8" [opcache] zend_extension=opcache.so opcache.enable=1 opcache.enable_cli=1 opcache.optimization_level=-1 opcache.fast_shutdown=1 opcache.validate_timestamps=1 opcache.revalidate_freq=60 opcache.use_cwd=1 opcache.max_accelerated_files=100000 opcache.max_wasted_percentage=5 opcache.memory_consumption=128 opcache.consistency_checks=0 opcache.huge_code_pages=1
纯 CPU 基准测试
基于Zend/bench.php的脚本测试
未开启 opcache
$ for i in `seq 1 10`;do /data/local/php71/bin/php /data/soft/php-7.2.0RC3/Zend/bench.php|grep 'Total'|awk '{print $0}' ;done Total 1.381 Total 1.416 Total 1.374 Total 1.366 Total 1.430 Total 1.394 Total 1.394 Total 1.369 Total 1.377 Total 1.358 # 取平均值 1.3859 $ for i in `seq 1 10`;do /data/local/php72/bin/php /data/soft/php-7.2.0RC3/Zend/bench.php|grep 'Total'|awk '{print $0}' ;done Total 1.448 Total 1.444 Total 1.445 Total 1.458 Total 1.440 Total 1.447 Total 1.486 Total 1.433 Total 1.449 Total 1.464 # 取平均值 1.4514
开启 opcache 之后
$ for i in `seq 1 10`;do /data/local/php71/bin/php /data/soft/php-7.2.0RC3/Zend/bench.php|grep 'Total'|awk '{print $0}' ;done Total 0.794 Total 0.797 Total 0.798 Total 0.806 Total 0.808 Total 0.793 Total 0.814 Total 0.846 Total 0.859 Total 0.818 # 取平均值 0.8133 $ for i in `seq 1 10`;do /data/local/php72/bin/php /data/soft/php-7.2.0RC3/Zend/bench.php|grep 'Total'|awk '{print $0}' ;done Total 0.779 Total 0.774 Total 0.765 Total 0.772 Total 0.764 Total 0.769 Total 0.779 Total 0.839 Total 0.784 Total 0.842 # 取平均值 0.7867
在本次测试中,未开启opcache的情况下,php7.2 性能反而有些下降,开启opcache之后,性能追赶上来,比php7.1略有提升。所以更应该开启opcache了。
基于Zend/micro_bench.php
的脚本测试
未开启 opcache
$ for i in `seq 1 10`;do /data/local/php71/bin/php /data/soft/php-7.2.0RC3/Zend/micro_bench.php|grep 'Total'|awk '{print $0}' ;done Total 5.588 Total 5.689 Total 5.652 Total 5.702 Total 5.668 Total 5.641 Total 5.622 Total 5.580 Total 5.635 Total 5.588 # 取平均值 5.6365 $ for i in `seq 1 10`;do /data/local/php72/bin/php /data/soft/php-7.2.0RC3/Zend/micro_bench.php|grep 'Total'|awk '{print $0}' ;done Total 5.924 Total 5.597 Total 5.553 Total 5.579 Total 5.591 Total 5.523 Total 5.518 Total 5.503 Total 5.494 Total 5.558 # 取平均值 5.584
开启 opcache
$ for i in `seq 1 10`;do /data/local/php71/bin/php /data/soft/php-7.2.0RC3/Zend/micro_bench.php|grep 'Total'|awk '{print $0}' ;done Total 4.369 Total 4.379 Total 4.352 Total 4.370 Total 4.375 Total 4.397 Total 4.311 Total 4.361 Total 4.313 Total 4.373 # 取平均值 4.36 $ for i in `seq 1 10`;do /data/local/php72/bin/php /data/soft/php-7.2.0RC3/Zend/micro_bench.php|grep 'Total'|awk '{print $0}' ;done Total 3.711 Total 3.711 Total 3.712 Total 3.734 Total 3.700 Total 3.712 Total 3.705 Total 3.769 Total 3.785 Total 3.695 # 取平均值 3.7234
在本次测试中,未开启opcache的情况下,php7.2 性能比php7.1 略有提升,开启opcache之后,php7.2比php7.1有很大的提升。
图表呈现
汇总 bench.php bench.php + opcache micro_bench.php micro_bench.php + opcache PHP7.1 1.3859 0.8133 5.6365 4.3600 PHP7.2 1.4514 0.7867 5.5840 3.7234
软件应用测试
配置说明
2核 Intel(R) Xeon(R) CPU E5-2640 0 @ 2.50GHz 内存 4G 系统 Centos 6.2 nginx 1.10.1 mysql 5.5.28 wordpress 4.8.1
考虑到该服务器上已经在运行我的博客等其他服务,所以php-fpm子进程数只配置了15个,在相同配置文件的条件下对比。
# php-fpm 简单配置,仅供测试 [global] pid = /data/local/php7{x}/var/run/php-fpm.pid error_log = /data/log/php7{x}-fpm.log log_level = notice [www] listen = /tmp/php7{x}-cgi.sock listen.backlog = -1 listen.allowed_clients = 127.0.0.1 listen.owner = www listen.group = www listen.mode = 0666 user = www group = www pm = static pm.max_children = 15
wordpress 压测
未开启 opcache
# php7.1 Concurrency Level: 10 Time taken for tests: 8.696 seconds Complete requests: 100 Failed requests: 0 Write errors: 0 Total transferred: 5215300 bytes HTML transferred: 5189300 bytes Requests per second: 11.50 [#/sec] (mean) Time per request: 869.637 [ms] (mean) Time per request: 86.964 [ms] (mean, across all concurrent requests) Transfer rate: 585.65 [Kbytes/sec] received # php7.2 Concurrency Level: 10 Time taken for tests: 8.528 seconds Complete requests: 100 Failed requests: 0 Write errors: 0 Total transferred: 5215500 bytes HTML transferred: 5189300 bytes Requests per second: 11.73 [#/sec] (mean) Time per request: 852.793 [ms] (mean) Time per request: 85.279 [ms] (mean, across all concurrent requests) Transfer rate: 597.24 [Kbytes/sec] received
可以看到在未开启opcache的情况下,性能非常糟糕,10个并发的情况下,每个请求的响应时间已经非常长了,没有必要继续增加并发数了。
开启 opcache 之后
汇总 7.1 Requests per second (每秒) 7.1 Time per request (ms) 7.2 Requests per second (每秒) 7.2 Time per request (ms) c10 n100 60.63 164.939 70.05 142.762 c20 n200 66.27 301.803 70.74 282.719 c30 n300 66.50 451.121 70.89 423.2 c40 n400 67.95 588.683 70.6 566.608
在开启opcache 之后,相对之前未开启的情况性能简直天壤之别。相比之下php7.2在wordpress压测上,QPS 稳定在70+ 相对php7.1 增加不少。
测试结果和配置参数以及服务器配置有关,仅供对比php7.1与7.2的性能。
感谢你能够认真阅读完这篇文章,希望小编分享PHP7.2、PHP7.1 性能对比的示例分析内容对大家有帮助,同时也希望大家多多支持创新互联网站建设公司,,关注创新互联行业资讯频道,遇到问题就找创新互联网站建设公司,,详细的解决方法等着你来学习!
网站名称:PHP7.2、PHP7.1性能对比的示例分析-创新互联
转载来源:http://lswzjz.com/article/cdpgcj.html