首页 > 开发 > PHP > 正文

PHP7正式版测试,性能惊艳!

2024-05-04 22:33:41
字体:
来源:转载
供稿:网友

我们今天就来看一下PHP 7正式版的算法和 wordpress 应用在其上的性能表现。

PHP7 的安装,真是非常地向下兼容,下载,解压,把之前的配置命令用上,一路回车下去,毫无违和感。为了不影响现有的环境的运行,所有专门开辟了目录 。

配置参数如下:

--prefix=/usr/local/php7 --with-config-file-path=/usr/local/php7/etc --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-mysqli --with-pdo-mysql --with-iconv-dir --with-freetype-dir --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 --with-mcrypt --enable-ftp --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --disable-fileinfo --enable-maintainer-zts

GCC 版本
据鸟哥建议,使用新一点的编译器, 推荐 GCC 4.8以上, 因为只有 GCC 4.8以上 PHP 才会开启 Global Register for opline and execute_data 支持, 这个会带来5%左右的性能提升。所以本实验选用的 GCC 版本为gcc version 4.8.2 20131212 (Red Hat 4.8.2-8) (GCC)。

安装好之后,做上软链接:

ln -s /usr/local/php7/bin/php /usr/bin/php7ln -s /usr/local/php7/bin/php-config /usr/bin/php7-config ln -s /usr/local/php7/bin/phpize /usr/bin/php7izeln -s /usr/local/php7/sbin/php-fpm /usr/sbin/php7-fpm

php7 -v 看到了我们熟悉的提示:

[root@localhost test]# php7 -vPHP 7.0.0 (cli) (built: Dec 2 2015 19:19:14) ( ZTS )Copyright (c) 1997-2015 The PHP GroupZend Engine v3.0.0, Copyright (c) 1998-2015 Zend Technologies

首先做的是性能评测,评测机型,首都在线云主机,4核 CPU Intel(R) Xeon(R) CPU E5-2680 0 @ 2.70GHz,内存4G,操作系统 Centos 6.5。

随便写了三段程序:

第一段,生成一个 60 万元素的数组,通过查找key 的方式,来确定key是否存在。

<?php$a = array();for($i=0;$i<600000;$i++){  $a[$i] = $i;}foreach($a as $i){ array_key_exists($i, $a);}

首先是 PHP 5.3.17 版。

[root@localhost test]# time php search_by_key.php real 0m0.389suser 0m0.337ssys  0m0.051s[root@localhost test]# time php search_by_key.php real 0m0.378suser 0m0.308ssys  0m0.062s[root@localhost test]# time php search_by_key.php real 0m0.378suser 0m0.317ssys  0m0.061s

其次是 PHP7 版。

[root@localhost php7]# time php7 search_by_key.phpreal 0m0.082suser 0m0.066ssys  0m0.014s[root@localhost php7]# time php7 search_by_key.phpreal 0m0.080suser 0m0.058ssys  0m0.021s[root@localhost php7]# time php7 search_by_key.phpreal 0m0.080suser 0m0.053ssys  0m0.026s`

这刚出手,就名不虚传,响应时间在PHP7下运行变为原来的1/4。真牛!

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表