This week saw two big events in programming languages in 2015, Swift open source and PHP7 release. Both of these events are historic events for the corresponding programming language.

Swift open source, let’s not talk about the matter, zhihu also has a heated discussion, today we will take a look at the official version of PHP 7 algorithm and wordpress application performance on it.

PHP7 installation, is really very compatible downward, download, decompress, use the previous configuration command, all the way to enter, no sense of violation. In order not to affect the operation of the existing environment, all special open directory.

Set the following parameters:

--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-ztsCopy the code

GCC version As suggested by Bird, With a newer compiler, GCC 4.8 or higher is recommended because Global Register for opline and execute_data support is not enabled for PHP until GCC 4.8 or higher, which results in a performance improvement of around 5%. Therefore, GCC version 4.8.2 20131212 (Red Hat 4.8.2-8) (GCC) was used in this experiment.

After installation, do soft link:

ln -s /usr/local/php7/bin/php /usr/bin/php7
ln -s /usr/local/php7/bin/php-config /usr/bin/php7-config 
ln -s /usr/local/php7/bin/phpize /usr/bin/php7ize
ln -s /usr/local/php7/sbin/php-fpm /usr/sbin/php7-fpmCopy the code

Php7-v sees the familiar prompt:

[root@localhost test]# php7 -V PHP 7.0.0 (cli) (built: Dec 2 2015 19:19:14) (ZTS) Copyright (C) 1997-2015 The PHP Group Zend Engine V3.0.0, Copyright (c) 1998-2015 Zend TechnologiesCopy the code

The first part is performance evaluation. The evaluation model is capital Online Cloud host with 4-core CPU Intel(R) Xeon(R) CPU E5-2680 0 @ 2.70ghz, MEMORY 4G, and operating system Centos 6.5.

I wrote three random programs:

The first section generates an array of 600,000 elements and determines the existence of the key by looking for it.

Copy the code

The first is PHP 5.3.17.

[root@localhost test]# time PHP search_by_key. PHP real 0m0.389s user 0m0.337s sys 0m0.051s [root@localhost test]# time PHP search_by_key.php real 0m0.378s user 0m0.308s sys 0m0.062s [root@localhost test]# time PHP search_by_key.php real 0m0.378s user 0m0.317s sys 0m0.061sCopy the code

Then there's PHP7.

[root@localhost php7]# time php7 search_by_key. PHP real 0m0.082s user 0m0.066s sys 0m0.014s [root@localhost php7]# time PHP php7 search_by_key.php real 0m0.080s user 0m0.058s sys 0m0.021s [root@localhost php7]# time php7 search_by_key.php real 0m0.080s user 0m0.058s sys 0m0.021s [root@localhost php7]# time php7 search_by_key.php real 0m0.00s user 0m0.053s sys 0m0.026s'Copy the code

The response time in PHP7 is up to a quarter of what it used to be. True cow! So I'm going to have to do two more, and the second one, it's going to be the same as above, but it's going to be slower, so it's going to be an array of 60,000 elements, looking for values. PHP code:

Copy the code

[root@localhost test]# time PHP search_by_val.php real 0m24.296s user 0m24.184s sys 0m0.025s [root@localhost test]# time PHP real 0m25.523s user 0m25.317s sys 0m0.026s [root@localhost test]# time PHP search_by_val.php real 0m26.026s user 0m25.478s sys 0m0.092sCopy the code

The wait, which always felt long, took more than 75 seconds, three tests. Now, PHP 7 comes into play.

[root@localhost php7]# time php7 search_by_val.php real 0m3.362s user 0m3.323s sys 0m0.007s [root@localhost php7]# time PHP php7 search_by_val.php real 0m3.266s user 0m3.251s sys 0m0.004s [root@localhost php7]# time php7 search_by_val.php real 0m3.290s user 0m3.275s sys 0M0.006sCopy the code

Oh, my God, no! That's nearly seven times faster. The author excited mood is difficult to express, and smoothly whole a more efficient prime algorithm. Figure out the number of primes up to 2,000,000, and this time we'll start with PHP7.

[root@localhost php7]# time php7 prime_v3.php 2000000 real 0m1.151s user 0m1.129s sys 0m0.010s [root@localhost php7]# PHP 2000000 real 0m1.141s user 0m1.123s sys 0m0.011s [root@localhost php7]# time php7 prime_v3.php 2000000 real 0m1.145s user 0m1.128s sys 0M0.010sCopy the code

The speed is steady at 1.2 seconds, while PHP 5.3 is a bit smaller this time, but PHP7 is also between three and four times as fast.

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

The prime algorithm is as follows, using a filter method. It is a relatively fast algorithm to find prime numbers.

$sqrt) { break; } } if(! $flag) { $ret[] = $i; } } echo (count($ret))."\n";Copy the code

So far, we've pretty much explained the problem. This code, without the use of complex libraries or a lot of networking and IO, is at least three times better optimized. This is really a historic advance. For example, in XHProf, there is an option, XHPROF_FLAGS_NO_BUILTINS, that does not analyze built-in functions or internal functions, such as arrays, dates, etc. That's where HHVM comes in, and that's what inspired PHP 7 today.

After a round of testing, I was intrigued to learn more about PHP 7 and to see how extensions and some common framework support worked, so I did the following two tests.

Remember in Alpha1 version, OneAPM is not supported, will it work this time? The author got oneAPm_PHP_agent_1.0.0.18.tar version, successfully installed.

Review images

The PHP 7 installation path was successfully identified.

The installation is successful.

For the extension, I have no confidence to test again, the following test two commonly used east, one is WordPress, although the website is harmonious, but what is the earth people know it. Another is ThinkPHP, which is the most widely used PHP development framework in the country, definitely number one, not one of them. I am also a fan of TP.

Should I praise them for their good work? I don't know if PHP 7 is compatible, but I've seen it work.Copy the code

The WordPress backend works fine with PHP 7 as a FastCGI backend.

Review images

The latest version of ThinkPHP, 3.2.3, works fine under PHP 7.

Review images

Finally, we did a stress test for two wordpress versions, one that was basically empty and just installed, and one that published several articles, and we tested it against the home page. Run tests in PHP5.5 and PHP7, with Zend OpCache on and off, respectively, to see if the response performance changes significantly. PHP 5.5.26 No Zend Opcache has article version with 20 concurrent entries

Review images

PHP 5.5.26 No Zend Opcache has article version with 10 concurrent entries

Review images

PHP 5.5.26 No Zend Opcache no article version, 20 concurrent entries

Review images

PHP 5.5.26 No Zend Opcache no article version, 10 concurrent entries

Review images

It can be seen that concurrency does not affect the total time. Compared with no articles, the total time of articles with articles is 6S slower, 20% slower on average. PHP 5.5.26 Zend OpCache PHP 5.5.26 Zend Opcache has article version, 20 concurrent

Review images

PHP 5.5.26 Zend Opcache has article version with 10 concurrent entries

Review images

PHP 5.5.26 has Zend Opcache without article version, 20 concurrent

Review images

PHP 5.5.26 has Zend Opcache without article version, 10 concurrent

Review images

Whether Zend OpCache is enabled or not has a significant impact on performance. For the version with articles, the increase is more than 2 times, and for the version without articles, the increase is more than 4 times.

Now let's test PHP7, again with the Zend OpCache free version for the first time. PHP 7 does not have Zend Opcache

Review images

2, PHP 7 no Zend Opcache version, 10 concurrent

Review images

As can be seen from the above data, there is a 30% performance improvement in PHP7 compared to PHP5.5.26. PHP7 no Zend Opcache no article version, 20 concurrent

Review images

PHP 7 no Zend Opcache no article version, 10 concurrent

Review images

The article free version is about 60% better than PHP5.5.26. Let's take a look at the version of Zend OpCache in PHP7. Note that unlike PHP5, Zend OpCache in PHP7 does not require an extension to be installed. You only need to add the following three lines to php.ini. zend_extension=opcache.so opcache.enable=1 opcache.enable_cli=1

PHP 7 has Zend Opcache with 20 concurrent entries

Review images

PHP 7 has Zend Opcache with 10 concurrent versions

Review images

PHP 7 has Zend Opcache with 20 concurrent entries

Review images

PHP 7 has Zend Opcache with 10 concurrent entries

Review images

Zend OpCache has a 5x performance improvement compared to 5.5.26 with Zend OpCache enabled. It can be said that Zend OpCache is critical for high concurrency performance.

So much for evaluating THE performance of PHP7, we have been excited to see the official release of PHP7 since the release of PHP7 Alpha in June. Once again, PHP7 is worth it. OneAPM for PHP is capable of reaching deep into all PHP applications for application performance management and monitoring, including code-level visibility of performance issues, quick identification and traceability of performance bottlenecks, real user experience monitoring, server monitoring, and end-to-end application performance management. PHP7 and OneAPM with Zend OpCache enabled are worth owning.