当前位置: 首页 > 后端技术 > PHP

PHP7.2和PHP7.1性能对比

时间:2023-03-29 22:17:57 PHP

直播好久没有曝光了,推荐一波《PHP进阶之路》.2更新内容https://github.com/php/php-sr...从官方文档来看,我似乎没有看到整体性能方面的任何变化。鸟哥点评,PHP7.2相比PHP7.1,主要的优化也在opcache。服务器配置2核Intel(R)Xeon(R)CPUE5-26400@2.50GHz内存4G系统Centos6.2gcc4.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=/数据/本地/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-vPHP7.1。10(cli)(内置:2017年10月8日16:08:01)(NTS)版权所有(c)1997-2017ThePHPGroupZendEnginev3.1.0,版权所有(c)1998-2017ZendTechnologies$/data/local/php72/bin/php-vPHP7.2.0RC3(cli)(内置:2017年10月8日18:11:35)(NTS)版权所有(c)1997-2017ThePHPGrouppZendEnginev3.2.0-dev,Copyright(c)1998-2017ZendTechnologiesphp.ini配置仅供测试,非生产环境使用,摘自http://www.laruence.com/2016/...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=1opcache.max_accelerated_files=100000opcache.max_wasted_percentage=5opcache.memory_consumption=128opcache.consistency_checks=0opcache.huge_code_pages=1opcache.max_accelerated_files=1opcache.bench.php脚本测试未开启inopcache`$110`;do/data/local/php71/bin/php/data/soft/php-7.2.0RC3/Zend/bench.php|grep'Total'|awk'{print$0}';doneTotal1.381Total1.416Total1.374Total1.366Total1.430Total1.394Total1.394Total1.369Total1.377Total1.358#average1.3859$foriin`seq110`;do/data/local/php72/bin/php/data/soft/php-7.2.0RC3/Zend/bench.php|grep'Total'|awk'{print$0}';doneTotal1.448Total1.444Total1.445Total1.458Total1.440Total1.447Total1.486Total1.433Total1.449Total1.464#取1.4514的平均值,打开opcacheafter$foriinseq110`;do/data/local/php71/bin/php/data/soft/php-7.2.0RC3/Zend/bench.php|grep'Total'|awk'{print$0}';doneTotal0.794Total0.797Total0.798Total0.806Total0.808Total0.793Total0.814Total0.846Total0.859Total0.818#i平均0.8133$`seq110`;做/data/local/php72/bin/php/data/soft/php-7.2.0RC3/Zend/bench.php|grep'Total'|awk'{print$0}';doneTotal0.779Total0.774Total0.765Total0.772Total0.764Total0.769Total0.779Total0.839Total0.784Total0.842#取0.7867的平均值。本次测试,在不启用opcache的情况下,php7.2的性能有所下降。开启opcache后,性能赶上来,相比php7.1略有提升,所以应该开启opcache。基于Zend/micro_bench.php的脚本测试没有为`seq110`中的i启用opcache$;do/data/local/php71/bin/php/data/soft/php-7.2.0RC3/Zend/micro_bench。PHP|grep'Total'|awk'{print$0}';doneTotal5.588Total5.689Total5.652Total5.702Total5.668Total5.641Total5.622Total5.580Total5.635Total5.588#average5.6365$foriin`seq`;do/10data/local/php72/bin/php/data/soft/php-7.2.0RC3/Zend/micro_bench.php|grep'Total'|awk'{print$0}';doneTotal5.924Total5.597Total5.553Total5.579Total5.591Total5.523Total5.518Total5.503Total5.494Total5.558#平均值5.584openopcache$foriin`seq110`;do/data/local/php71/bin/php/data/soft/php-7.2.0RC3/Zend/micro_bench.php|grep'Total'|awk'{print$0}';doneTotal4.369Total4.379Total4.352Total4.370Total4.375Total4.397Total4.311Total4.361Total4.313Total4.373#average4.36$foriin`seq110`;do/data/local/php72/bin/php/data/soft/php-7.2.0RC3/Zend/micro_bench.php|grep'Total'|awk'{print$0}';doneTotal3.711Total3.711Total3.712Total3.734Total3.700Total3.712Total3.705Total3.769Total3.785Total343.7#2averageInthistest,在不启用opcache的情况下,php7.2的性能相比php7.1略有提升。启用opcache后,php7.2相比php7.1有了很大的提升图表演示总结bench.phpbench.php+opcachemicro_bench.phpmicro_bench.php+opcachePHP7.11.38590.81335.63654.3600PHP7.21.45140.78675.58403.7234软件应用测试配置说明2-coreIntel(R)Xeon(R)CPUE5-26400@2.50GHz内存4G系统Centos6.2nginx1.10.1mysql5.5.28wordpress4.8.1考虑到我的博客等服务已经在这台服务器上运行,所以php-fpm子进程数只配置为15个。在相同配置文件条件下比较。#php-fpm简单配置,仅提供测试[global]pid=/data/local/php7{x}/var/run/php-fpm.piderror_log=/data/log/php7{x}-fpm.loglog_level=notice[www]listen=/tmp/php7{x}-cgi.socklisten.backlog=-1listen.allowed_clients=127.0.0.1listen.owner=wwwlisten.group=wwwlisten.mode=0666user=wwwgroup=wwwpm=staticpm.max_children=15wordpress压测未开启opcache#php7.1并发级别:10测试时间:8.696秒完成请求:100失败请求:0写入错误:0总传输:5215300字节HTML传输:5189300字节每秒请求:11.50[#/sec](平均值)每个请求的时间:869.637[ms](平均值)每个请求的时间:86.964[ms](平均值,跨所有并发请求)传输速率:585.65[Kbytes/sec]received#php7.2ConcurrencyLevel:10Timetakenfortests:8.528secondsCompleterequests:100Failed请求:0写入错误:0总转移:5215500bytesHTML传输:5189300字节每秒请求数:11.73[#/sec](平均值)每个请求时间:852.793[ms](平均值)每个请求时间:85.279[ms](平均值,跨所有并发请求)传输速率:597.24[Kbytes/sec]received可以看到在不启用opcache的情况下,性能很差。在10个并发的情况下,每个请求的响应时间已经很长了。没有必要继续增加并发数。启用opcache后,总结7.1Requestspersecond(每秒)7.1Timeperrequest(ms)7.2Requestspersecond(每秒)7.2Timeperrequest(ms)c10n10060.63164.93970.05142.762c20n20066.27301.80370.74282.719c30n30066。50451.12170.89423.2c40n40067.95588.68370.6566.608opcache开启后,性能和之前没有开启的情况有很大的不同。相比之下,在php7.2的wordpress压测中,QPS稳定在70+,相比php7.1有了不小的提升。测试结果与配置参数和服务器配置有关,仅用于比较php7.1和7.2的性能。其他让你的PHP更快的方法,请参考@Laruencehttp://www.laruence.com/2015/...