Home >Backend Development >PHP Tutorial >Detailed graphic and text explanation of php7 usage experience: greatly improved performance, strong compatibility and insufficient extension support

Detailed graphic and text explanation of php7 usage experience: greatly improved performance, strong compatibility and insufficient extension support

黄舟
黄舟Original
2017-07-27 14:55:101738browse

This article mainly introduces the performance improvement, strong compatibility, and insufficient expansion support of PHP 7 installation and use experience (be careful when upgrading PHP). It is of great practical value. Friends in need can refer to it

With the release of PHP 7, the performance and compatibility of PHP 7 have become a hot topic of discussion in recent days. The high performance of PHP 7 has made many people ready to take action, and some are "early adopters". "Friends have already applied PHP 7 to the production environment. At the same time, popular applications such as LNMP have also been updated in a timely manner and have begun to support PHP 7.

When it comes to PHP performance issues, I have to mention the HHVM shared before. This is a tool developed by Facebook to improve PHP performance. It uses Just-In-Time (JIT) compilation method to convert PHP code. into some kind of bytecode. During the actual testing process, HHVM was a qualitative leap in improving the performance of PHP. The efficient PHP running environment improved PHP performance by more than 9 times.

In recent years, PHP has been widely criticized for its performance bottleneck. Many developers have abandoned PHP and fled. The perfect performance of HHVM is very detrimental to the development of PHP. PHP 7 is the PHP community's response to HHVM. The official release version of PHP 7 has greatly improved PHP performance. Actual tests have found that the performance of PHP 7 exceeds that of HHVM on some occasions.

This article will bring you the installation and usage experience of PHP 7. Friends who want to eagerly experience the performance of PHP 7 should do several more program compatibility tests before officially upgrading PHP. Although the official said PHP 7 has 99% backward compatibility, but to be on the safe side we still need to be cautious when applying it to production environments.

PHP 7 installation and use experience: greatly improved performance, strong compatibility, insufficient extension support, be cautious when upgrading PHP

1. Give full play to the high performance of PHP 7 Several key points

PHP 7 can be said to have a qualitative leap in performance compared to the previous PHP version, but as the saying goes "a good horse goes with a good saddle, a good car goes with a sail", if you want to give full play to The performance advantages of PHP 7 also require preparation from the following aspects: (This part is quoted from PHP7 core developer, author of Yaf, Yar, Yac and other projects: Laruence).

1. Remember to enable Zend Opcache. Enabling Opcache is very simple. Add:


zend_extension=opcache.so
opcache.enable=1
opcache.enable_cli=1"
# to the php.ini configuration file. ##2. When using a new compiler, GCC 4.8 or above is recommended, because only GCC 4.8 or above PHP 7 will enable Global Register for opline and execute_data support, which will bring about a 5% performance improvement.

3. Enabling HugePage will make PHP 7 faster. First, enable HugePages in the system, and then enable Opcache's huge_code_pages. Taking CentOS 6.5 as an example, pass the command: $sudo sysctl vm.nr_hugepages=512, allocate 512 reserved huge page memory:


$ cat /proc/meminfo | grep Huge
AnonHugePages:  106496 kB
HugePages_Total:   512
HugePages_Free:   504
HugePages_Rsvd:    27
HugePages_Surp:    0
Hugepagesize:    2048 kB

Then add: opcache.huge_code_pages=1 to php.ini, this way , PHP will use large memory pages to save its own text segments and huge memory allocations, reducing TLB misses and improving performance.

4. Turn on Opcache File Cache (experimental), by turning on This allows Opcache to cache the opcode cache in an external file. For some scripts, there will be a significant performance improvement. The method is to add: opcache.file_cache=/tmp to php.ini. In this way, PHP will cache some Opcode binary export files in the /tmp directory, which can exist across the PHP life cycle.

5. PGO. If your PHP is specifically designed to serve one project, such as just for your WordPress, or Drupal, or something else, then you can try to use PGO to improve PHP and specifically improve the performance of your project. Specifically, taking wordpress 4.1 as the optimization scenario... First, when compiling PHP: $ make prof-gen.

6. Then use your project to train PHP, for example, for WordPress:$ sapi/cgi/php-cgi -T 100 /home/huixinchen/local/www/htdocs/wordpress/index.php >/ dev/null, that is, let php-cgi run the WordPress homepage 100 times, thereby generating some profile information in the process. Finally:


$ make prof-clean
$ make prof-use && make install

7. The PHP7 you compile at this time is the highest performance compiled version tailored for your project.

2. PHP 7 installation and compilation

1. PHP 7 official website:

2. Hands-on ability Friends who are strong can go directly to the official website to download PHP 7, and then manually edit and install it. If you are accustomed to using the lnmp.org webmaster's LNMP one-click installation package, you can try the release of the LNMP 1.3 beta version, which has added support for php7: a method for smoothly migrating the website to the LNMP or LAMP website building environment.

3. The LNMP installation package provided by OneinStack already has one-click installation for PHP 7. When executing the script, you can choose PHP 7 installation. PHP 7 currently only has the official Zend Opcache extension available for installation. .

4. OneinStack installed PHP 7 successfully.

5. This is PHP 7 information display.

6. This is the Opcache control panel for PHP 7 provided by OneinStack.

3. Performance comparison between PHP 7 and old versions of PHP and HHVM

1. This is PHP 7 tested by foreign developers Compared with the performance of PHP 5.6 under popular programs such as WordPress and Drupal, it is obvious that the performance of PHP 7 has improved a lot.

2. For programs such as WordPress, PHP 7 not only improves the individual execution speed, but also increases the performance the longer WordPress runs on PHP 7.

3. As mentioned above, PHP 7’s performance improvement for PHP has surpassed HHVM in some aspects. This is PHP 5.6 given by the official website of zend.com abroad. , PHP 7, HHVM execution efficiency comparison results under different programs.

4. Test the execution efficiency of PHP 5.6, PHP 7, and HHVM on the professional open source e-commerce system Magento. PHP 7 is twice as fast as PHP 5.6, and the memory usage is 30% lower than PHP 5.6. .

5. The efficiency of testing PHP 7 on Drupal 8 is the fastest, surpassing HHVM.

#6. During the WordPress test, it was found that PHP 5.6 requires 100MB of memory to execute, while PHP 7 only requires 25MB.

7. In terms of different program execution speeds, PHP 7 is obviously the leader. Ruby 2.1, Python 2.7.8, and Perl 5.18.4 are all behind PHP 7.

4. PHP 7 performance test results report

1. It is unfounded to say, what is the performance of PHP 7 running program? Woolen cloth? Here, the tribe uses a brand new WordPress as the test object. The WordPress homepage loading time test running on PHP 7 shows 0.029 seconds, and the memory is 3.39MB.

2. This is the page loading time of the same WordPress page running PHP 5.6: 1.955 seconds, and the memory occupied is 3.92MB. From the data point of view, PHP 7 has completely defeated PHP 5.6.

3. The efficiency of running WordPress in PHP 7 has indeed been qualitatively improved compared to the previous version. In order to fully understand the performance of PHP 7, here is the Web performance according to the website server pressure. The test method is to use Webbench to simulate 200 and 400 connections within 10 seconds, and the speed is more than 8000 pages/minute.

#4. At this time, the VPS server system load is 3.49.

#5. Increase the number of simulated connections to 1,600, and the speed remains above 8,000 pages/minute.

#6. At this time, the VPS server system load is 17, which should be a bit difficult.

#7. Increase the number of simulated connections to 5000, the speed is 4800 pages/minute, and the speed begins to slow down.

#8. At this time, the VPS server system load is 23, and the server is overloaded.

9. In order to test the endurance limit of PHP 7 on this VPS host, Webbench simulated 10,000 connections to continuously access the server for 20 seconds.

10. At this time, the system load of the VPS server is nearly 90, which should have reached the limit, but the server still does not crash.

11. Next, let’s take a look at the stress test results of the same configured VPS host running WordPress. First, use Webbench to simulate 200 and 400 connections in 10 seconds. The speed is 3600 pages/minute, which is half as slow as the PHP 7 test above.

12. This is the system load of PHP 5.6 testing 200 and 400 connections. It has reached 10, which is obviously beyond the 3.49 tested in the PHP 7 environment.

13. In the PHP 5.6 test, the number of simulated connections was increased to 1000 and 2000. At this time, the speed has dropped to 1600 pages/minute, and the number of successful connections has also dropped to 500. Around 2,700 when tested with PHP 7.

14. At this time, the system load has reached 17.

15. Use Webbench to test the number of connections in PHP 5.6 to 10,000, and continuously access the server within 20 seconds. At this point, the test is stuck with no results.

#16. The system load of the VPS server here has reached more than 1,000, and the server has crashed.

17. The WordPress website under PHP 5.6 has been down.

5. PHP 7 compatibility issues

1. Currently, domestic Discuz, etc. do not support PHP 7, and PHP extensions do not Only the official Opcache can be used, others such as eAccelerator, xcache, memcached, etc. You can always pay attention to the extended support list:

2. After testing, PHP 7 runs WordPress There is no problem.

#3. There is no problem installing the WordPress plug-in on PHP 7.

4. PHP 7 may have incompatibility issues with some functions, operators, etc., but 99% of programs may not use these.

6. Summary of PHP 7 installation and use experience

1. One surprise after using PHP 7 is that, as tested by foreign developers, the performance of PHP 7 is basic It is on par with HHVM. Since HHVM uses a just-in-time compiler to compile PHP code into machine instructions, many PHP programs need to be improved when running on HHVM.

2. PHP 7 has the ultra-high performance of HHVM, and at the same time has the advantage of PHP's backward compatibility. I believe that PHP 7 will be recognized and accepted by more and more people in the near future. Although there are currently not many cache, acceleration and other extensions that support PHP 7, it is only a matter of time. More and more developers will join the ranks of PHP 7 development.

The above is the detailed content of Detailed graphic and text explanation of php7 usage experience: greatly improved performance, strong compatibility and insufficient extension support. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn