认识PHP7.2、PHP7.1 性能对比

广告:宝塔服务器面板,一键全能部署及管理,送你10850元礼包,点我领取~~~

认识PHP7.2、PHP7.1 性能对比

php7教程栏目介绍PHP7.2、PHP7.1的性能对比。

推荐:PHP7教程

服务器配置

2核 Intel(R) Xeon(R) CPU E5-2640 0 @ 2.50GHz内存 4G系统 Centos 6.2gcc 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 -vPHP 7.1.10 (cli) (built: Oct  8 2017 16:08:01) ( NTS )Copyright (c) 1997-2017 The PHP GroupZend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
登录后复制
$ /data/local/php72/bin/php -vPHP 7.2.0RC3 (cli) (built: Oct  8 2017 18:11:35) ( NTS )Copyright (c) 1997-2017 The PHP GroupZend Engine v3.2.0-dev, Copyright (c) 1998-2017 Zend Technologies
登录后复制

php.ini 配置

仅供测试,非生产环境使用,摘录自 www.laruence.com/2016/12/18/…

engine = Onshort_open_tag = Offrealpath_cache_size = 2Mmax_execution_time = 86400memory_limit = 1024Merror_reporting = 0display_errors = 0display_startup_errors = 0log_errors = 0default_charset = "UTF-8" [opcache]zend_extension=opcache.soopcache.enable=1opcache.enable_cli=1opcache.optimization_level=-1opcache.fast_shutdown=1opcache.validate_timestamps=1opcache.revalidate_freq=60opcache.use_cwd=1opcache.max_accelerated_files=100000opcache.max_wasted_percentage=5opcache.memory_consumption=128opcache.consistency_checks=0opcache.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.381Total              1.416Total              1.374Total              1.366Total              1.430Total              1.394Total              1.394Total              1.369Total              1.377Total              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.448Total              1.444Total              1.445Total              1.458Total              1.440Total              1.447Total              1.486Total              1.433Total              1.449Total              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}' ;doneTotal              0.794Total              0.797Total              0.798Total              0.806Total              0.808Total              0.793Total              0.814Total              0.846Total              0.859Total              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}' ;doneTotal              0.779Total              0.774Total              0.765Total              0.772Total              0.764Total              0.769Total              0.779Total              0.839Total              0.784Total              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}' ;doneTotal              5.588Total              5.689Total              5.652Total              5.702Total              5.668Total              5.641Total              5.622Total              5.580Total              5.635Total              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}' ;doneTotal              5.924Total              5.597Total              5.553Total              5.579Total              5.591Total              5.523Total              5.518Total              5.503Total              5.494Total              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}' ;doneTotal              4.369Total              4.379Total              4.352Total              4.370Total              4.375Total              4.397Total              4.311Total              4.361Total              4.313Total              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}' ;doneTotal              3.711Total              3.711Total              3.712Total              3.734Total              3.700Total              3.712Total              3.705Total              3.769Total              3.785Total              3.695# 取平均值 3.7234
登录后复制

在本次测试中,未开启opcache的情况下,php7.2 性能比php7.1 略有提升,开启opcache之后,php7.2比php7.1有很大的提升。

图表呈现

# 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-xsl0
登录后复制

软件应用测试

配置说明

# 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-xsl1
登录后复制

考虑到该服务器上已经在运行我的博客等其他服务,所以php-fpm子进程数只配置了15个,在相同配置文件的条件下对比。

# 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-xsl2
登录后复制

wordpress 压测

未开启 opcache

# 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-xsl3
登录后复制

可以看到在未开启opcache的情况下,性能非常糟糕,10个并发的情况下,每个请求的响应时间已经非常长了,没有必要继续增加并发数了。

开启 opcache 之后

# 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-xsl4
登录后复制

在开启opcache 之后,相对之前未开启的情况性能简直天壤之别。相比之下php7.2在wordpress压测上,QPS 稳定在70+ 相对php7.1 增加不少。

测试结果和配置参数以及服务器配置有关,仅供对比php7.1与7.2的性能。

以上就是认识PHP7.2、PHP7.1 性能对比的详细内容,更多请关注9543建站博客其它相关文章!

9543建站博客
一个专注于网站开发、微信开发的技术类纯净博客。
作者头像
admin创始人

肥猫,知名SEO博客站长,14年SEO经验。

上一篇:淘宝如何用css
下一篇:PHP8中函数调用的灵活性,使得极其复杂的代码可以轻松实现

发表评论

关闭广告
关闭广告