PHP 7 official version test, amazing performance!

Source: Internet
Author: User
This week ushered in two major events in the programming language field in 2015: the release of Swift7 open source and PHP7, both of which are events that can be loaded into the corresponding programming language history, if you are interested, let's take a look at the official PHP 7 algorithm and the performance of wordpress applications.

PHP 7 installation is very backward compatible, download, decompress, use the previous configuration commands, and press enter all the way, without any violation. In order not to affect the running of the existing environment, all directories are specially opened.

The configuration parameters are as follows:

--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 version
According to laruence's suggestion, we recommend GCC 4.8 or above to use a new compiler, because only PHP above GCC 4.8 will enable Global Register for opline and execute_data support, this will increase the performance by about 5%. Therefore, the GCC version used in this experiment is gcc version 4.8.2 20131212 (Red Hat 4.8.2-8) (GCC ).

After installation, make the soft link:

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-vWe are familiar with the following tips:

[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

The first thing we do is performance evaluation, evaluation model, Capital online cloud host, 4-core CPU Intel (R) Xeon (R) CPU E5-2680 0 @ 2.70 GHz, memory 4G, centos 6.5.

I casually wrote three programs:

In the first section, an array of 0.6 million elements is generated. The key is queried to determine whether the key exists.

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

FirstPHP 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

SecondPHP 7.

[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`

This was just launched, and the response time changed to 1/4 in PHP 7. Zhenniu!
I have to try it again. The second part is still in the above method. However, due to the slow speed, it becomes an array of 60000 elements to find the value.
The code is as follows:
Php code:

<?php$a = array();for($i=0;$i<600000;$i++){  $a[$i] = $i;}foreach($a as $i){ array_key_exists($i, $a);}[root@localhost test]# time php search_by_val.php real 0m24.296suser 0m24.184ssys  0m0.025s[root@localhost test]# time php search_by_val.php real 0m25.523suser 0m25.317ssys  0m0.026s[root@localhost test]# time php search_by_val.php real 0m26.026suser 0m25.478ssys  0m0.092s

The waiting time is always long. it takes more than 75 seconds for three Tests. Next, PHP 7 is on the stage.

[root@localhost php7]# time php7 search_by_val.phpreal 0m3.362suser 0m3.323ssys  0m0.007s[root@localhost php7]# time php7 search_by_val.phpreal 0m3.266suser 0m3.251ssys  0m0.004s[root@localhost php7]# time php7 search_by_val.phpreal 0m3.290suser 0m3.275ssys  0m0.006s

Yes! The speed has increased by nearly seven times.
I was so excited that it was difficult to explain, and successfully completed a more efficient prime number algorithm. Calculate the number of prime numbers less than 2000000. this time we start PHP7.

[root@localhost php7]# time php7 prime_v3.php 2000000real 0m1.151suser 0m1.129ssys  0m0.010s[root@localhost php7]# time php7 prime_v3.php 2000000real 0m1.141suser 0m1.123ssys  0m0.011s[root@localhost php7]# time php7 prime_v3.php 2000000real 0m1.145suser 0m1.128ssys  0m0.010s`

Stable speed at 1.2 S
In PHP 5.3, this time the gap is smaller than the previous one, but PHP7 is also three to four times faster.

[root@localhost test]# time php prime_v3.php 2000000prime number count under 2000000 is :148933real 0m4.425suser 0m4.380ssys  0m0.023s[root@localhost test]# time php prime_v3.php 2000000prime number count under 2000000 is :148933real 0m4.457suser 0m4.414ssys  0m0.032s[root@localhost test]# time php prime_v3.php 2000000prime number count under 2000000 is :148933real 0m4.464suser 0m4.399ssys  0m0.046s

The prime number algorithm is as follows, which uses the limit method. Relatively, the algorithm is used to calculate prime numbers quickly.

<?php/*  * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */$num = $argv[1];$ret = array(2);$flag = false;for($i=3; $i<=$num; $i+=2){ $flag = false; $sqrt = sqrt($i); foreach($ret as $prime) {  if($i%$prime == 0)  {   $flag = true;   break;  }  if($prime>$sqrt)  {   break;  } } if(!$flag) {  $ret[] = $i; }}echo (count($ret))."\n";

At this point, we can basically explain the problem. These codes do not use complex function libraries, nor have a large number of networks and I/O operations, but the performance has been optimized by at least three times. This is a historic progress. In our past performance evaluations, language-level performance is often ignored. why? for example, in XHProf, XHPROF_FLAGS_NO_BUILTINS, this function is used to analyze built-in functions or internal functions, such as arrays and dates. Because we often miss the space for improvement, and of course, the average person cannot do it, so we have HHVM and inspired PHP 7 today.

After a round of tests, I became more interested in PHP 7,I would like to see how the extension and some common framework support are. I just did the following two Tests.

I remember that in Alpha1, OneAPM was not supported, but this time it didn't work? I got OneApm_php_Agent_1.0.0.18.tar and installed it smoothly.

Successfully identified the installation path of PHP 7.

The installation is successful.

I don't have the confidence to continue with the expansion test. below I will test two common Dongdong, Wordpress. although the website is in harmony, everyone on earth knows it. The other is ThinkPHP, which is the most widely used PHP development framework in China. it is definitely the first, not one. I am also a fan of TP.

Should we boast that these two software are doing well? I still don't know whether PHP 7 can be well compatible. However, I can see that it is initially normal.
The Wordpress backend runs normally when PHP 7 is used as the FastCGI backend.


The latest ThinkPHP version 3.2.3 runs normally in PHP 7.


Finally, let's do a stress test. There are two wordpress, one is the installed version that is basically empty, and the other is the version that has published several articles. we will test the homepage. Perform tests in PHP5.5 and PHP7 respectively, and enable and disable Zend OpCache respectively to check whether the response performance has changed significantly.
1. PHP 5.5.26 no Zend Opcache has article version, 20 concurrency


2. PHP 5.5.26 without Zend Opcache has article version and 10 concurrency


3. PHP 5.5.26, no Zend Opcache, no article version, 20 concurrency


4. PHP 5.5.26, no Zend Opcache, no article version, 10 concurrency


It can be seen that concurrency does not affect the total time. some articles are 6 S slower than the total time, and the average speed is 20%.
Next we will open the Zend OpCache of PHP 5.5.26.

1. PHP 5.5.26 has Zend Opcache and 20 concurrent

2. PHP 5.5.26 has Zend Opcache, article version, and 10 concurrency

3. PHP 5.5.26 has Zend Opcache and 20 concurrent jobs.


4. PHP 5.5.26 has Zend Opcache, no article version, and 10 concurrency


It can be seen that whether to enable Zend OpCache has a significant impact on performance. The article version has been improved by more than 2 times, and the article version has been improved by more than 4 times.

Next we will test PHP7. the first time is that there is no Zend OpCache version.
1. PHP 7 without Zend Opcache with article version, 20 concurrency


2. PHP 7 without Zend Opcache with article version and 10 concurrency


From the above data, we can see that PHP7 has improved performance by about 30% compared with php5.26. let's take a look at the article version.

3. PHP7 without Zend Opcache, no article version, 20 concurrency


4. PHP 7, no Zend Opcache, no article version, 10 concurrency

Compared with PHP5.5.26, php5.26 has improved by about 60%. Next, let's take a look at the Zend OpCache version under PHP7.
Note that the Zend OpCache of php 7 is different from that of PHP5. you do not need to install the extension. you only need to add the following three lines in php. ini.
Zend_extension = opcache. so
Opcache. enable = 1
Opcache. enable_cli = 1

1. PHP 7 has Zend Opcache, article version, and 20 concurrency


2. PHP 7 has Zend Opcache, article version, and 10 concurrency


3. PHP 7 has Zend Opcache, no article version, and 20 concurrency


4. PHP 7 has Zend Opcache, no article version, and 10 concurrency


Too invincible. enabling Zend OpCache has improved the performance by more than 5 times. compared with enabling Zend OpCache 5.5.26, Zend OpCache has also improved the performance by at least 3 times. It can be said that Zend OpCache is critical for high concurrency performance.

The performance evaluation of PHP 7 is here. since the release of PHP7 alpha in May, we are delighted to wait for the release of the official PHP 7 version. The reevaluation proves that PHP7 is worth your own. OneAPM for PHP can go deep into all PHP applications to complete application performance management and monitoring, including visibility of code-level performance problems, fast identification and tracing of performance bottlenecks, Real User Experience Monitoring, server monitoring, and end-to-end application performance management. PHP 7 and OneAPM with Zend OpCache enabled are worth your attention.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.