PHP 7 Installation and Use experience greatly improves performance, strong compatibility, and insufficient Scalability (be cautious when upgrading PHP). Be cautious when installing and using PHP 7.

Source: Internet
Author: User
Tags hhvm website server drupal vps server

PHP 7 Installation and Use experience greatly improves performance, strong compatibility, and insufficient Scalability (be cautious when upgrading PHP). Be cautious when installing and using PHP 7.


With the release of PHP 7, the performance and compatibility of PHP 7 have become a hot topic for discussion over the past few days. The high performance of PHP 7 has made many people eager to get started, some "early adopters" have applied PHP 7 to the production environment. At the same time, popular apps such as LNMP were also updated in a timely manner, and they began to support PHP 7 in succession.

Speaking of PHP performance, I have to say the previously shared HHVM, a tool developed by Facebook to improve PHP performance, using Just-In-Time (JIT) compile PHP code to a certain bytecode. During the actual test, HHVM's Performance Improvement for PHP is a qualitative leap, and the efficient PHP runtime environment improves PHP performance by more than 9 times.

In recent years, PHP has been widely criticized as a performance bottleneck problem. Many developers have abandoned PHP and fled. The perfect performance of HHVM is very unfavorable for the development of PHP. PHP 7 is the response of the PHP community to HHVM. The official release of PHP 7 has greatly improved the PHP performance. In some cases, it is found that the performance of PHP 7 exceeds HHVM.

This article will bring you a PHP 7 Installation and Use experience. If you are eager to experience the PHP 7 performance, you 'd better perform several program compatibility tests before officially upgrading PHP, although the official saying that PHP 7 has 99% backward compatibility, we still need to exercise caution when applying it to the production environment for the sake of insurance.

PHP 7 installation experience: high performance, strong compatibility, and insufficient scalability. Be cautious when upgrading PHP.

I. Key Points of making full use of PHP 7's High Performance

Compared with the previous PHP version, PHP 7 has a qualitative leap in performance, but the so-called "good horse with good saddle, good car with sail" wants to take advantage of the performance advantages of PHP 7, you also need to prepare from the following aspects: (this part is derived from PHP7 core developers, Yaf, Yar, Yac, and other projects: Laruence ).


1. Remember to enable Zend Opcache. It is very easy to enable Opcache. Add the following to the php. ini configuration file:

zend_extension=opcache.so
opcache.enable=1
opcache.enable_cli=1"

2. Using the new compiler, we recommend GCC 4.8 or above, because only GCC 4.8 or above PHP 7 will enable Global Register for opline and execute_data support, which will bring about 5% performance improvement.


3. enabling HugePage helps PHP 7 to be faster. First, enable HugePages in the system, and then enable huge_code_pages of Opcache. Taking CentOS 6.5 as an example, run the command: $ sudo sysctl vm. nr_hugepages = 512, allocate 512 reserved large 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 in php. add: opcache to ini. huge_code_pages = 1. In this way, PHP will save its text segment and the huge in memory allocation by using a large memory page to reduce TLB miss and thus improve performance.

4. Enable Opcache File Cache (experimental). By enabling this, Opcache can Cache opcode to external files, which significantly improves the performance of some scripts. Add opcache. file_cache =/tmp to php. ini. In this way, PHP will Cache some Opcode binary export files under the/tmp directory, which can exist across the PHP lifecycle.

5. PGO. If your PHP is dedicated to a project, for example, just for your Wordpress, drupal, or anything else, then you can try to improve PHP through PGO, improves the performance of your project. Specifically, we use wordpress 4.1 as the optimization scenario. First, when compiling PHP, we should first: $ make prof-gen.

6. Use your project to train PHP, for example, 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 to generate some profile information in this process. Finally:

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

7. At this time, the PHP 7 compiled by you is the best compilation version tailored for your project.


Ii. Install and compile PHP 7

1. PHP 7 Official Website:

1. Official Website: http://php.net/

2. Download: http://php.net/downloads.php?this site: Click to download

2. If you have strong hands-on skills, you can download PHP 7 from the official website and manually edit and install it. If you are used to using the LNMP one-key installation package of lnmp.org webmaster, you can try to release the LNMP 1.3 Test version. You have added php7 support: the method for smoothly migrating your website to the LNMP or LAMP environment.

3. The LNMP installation package provided by OneinStack has been installed with PHP 7 with one click. When executing the script, you can select PHP 7 for installation, PHP 7 currently only comes with the official Zend Opcache extension for installation.


4. OneinStack is installed successfully in PHP 7.


5. This is the PHP 7 Information Display.


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


Iii. Performance Comparison between PHP 7 and earlier versions of PHP and HHVM

1. This is the performance of PHP 7 and PHP 5.6 tested by foreign developers in popular programs such as Wordpress and Drupal. The results show that the performance of PHP 7 is significantly improved.


2. PHP 7 not only improves the execution speed of a single Wordpress program, but also improves the performance as Wordpress runs on PHP 7 for a longer time.


3. As mentioned above, PHP 7's Performance Improvement for PHP has exceeded HHVM in some aspects, this is the result of comparing the execution efficiency of PHP 5.6, PHP 7, and HHVM in different programs provided by zend.com.

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 the running speed of PHP 5.6, the memory usage is 5.6 lower than that of PHP 30%.


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


6. During the Wordpress test, it was found that PHP 5.6 requires MB of memory, while PHP 7 only needs 25 MB.


7. PHP 7 is clearly leading the execution speed of different programs. Ruby 2.1, Python 2.7.8, and Perl 5.18.4 are inferior to PHP 7.


Iv. PHP 7 performance test result report

1. What is the performance of the PHP 7 running program? Here the tribe uses a brand new Wordpress as the test object. The loading time of the Wordpress homepage running on PHP 7 is 0.029 seconds, and the memory is 3.39 MB.


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


3. The efficiency of running Wordpress in PHP 7 has indeed been significantly improved compared with the previous version. To fully understand the performance of PHP 7, We will test the Web performance based on the pressure on the website server, use Webbench to simulate 200 or 400 connections in 10 seconds. The speed is over 8000 pages/minute.


4. The system load of the VPS server IS 3.49.


5. Increase the number of simulated connections to 1600 and keep the speed above 8000 pages/minute.


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


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


8. At this time, the system load of the VPS server is 23, and the server is too heavy.


9. To test the limits of PHP 7 on the capacity of the current VPS host, Webbench simulates 10000 connections to continuously access the server in 20 seconds.


10. At this time, the system load of the VPS server is nearly 90, and it should have reached the limit, but the server is still not dead.


11. Next, let's take a look at the stress test results of running Wordpress on the same VPS host. First, we use Webbench to simulate 200 or 400 connections in 10 seconds, the speed is 3600 page/minute, which is half the speed of the above PHP 7 test.


12. This is the system load for testing 5.6 and 200 connections in PHP 400, which has reached 10, significantly exceeding 3.49 tested in PHP 7.


13. In the PHP 5.6 test, the number of simulated connections is 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 about 500, far less than 2700 in PHP 7 testing.


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


15. Use Webbench in PHP 5.6 to test the number of connections as 10000, and continuously access the server within 20 seconds. The test is stuck and no result is returned.


16. The system load of the VPS server has reached more than 1000, and the server has crashed.


17. The Wordpress website under PHP 5.6 is down.


V. compatibility issues in PHP 7

1. Currently, Discuz in China does not support PHP 7, and PHP extensions can only be used by the official Opcache. Others include eAccelerator, xcache, and memcached, you can follow the extended support list at any time: https://github.com/gophp7/gophp7-ext/wiki/extensions-catalog. Php memcache extensions are available: https://github.com/php-memcached-dev/php-memcached/tree/php7 and https://github.com/websupport-sk/pecl-memcache. Thank you for your reminder.


2. After testing, PHP 7 runs Wordpress without any problems.


3. There is no problem with installing the Wordpress plug-in on PHP 7.


4. Some functions and operators in PHP 7 may be incompatible, but these may not be used by 99% of programs.

Vi. Summary of PHP 7 installation experience

1. One of the surprises after using PHP 7 is that, as tested by foreign developers, the performance of PHP 7 is basically the same as that of HHVM, because HHVM uses real-Time (Just In Time) the compiler compiles PHP code to machine commands, so many PHP programs run on HHVM need to be improved.

2. PHP 7 has the ultra-high performance of HHVM and the backward compatibility advantage of PHP. I believe that PHP 7 will be recognized and accepted by more and more people in the near future. Although PHP 7 supports a small number of extensions such as caching and acceleration, it is only a matter of time. More and more developers will join the development of PHP 7.

The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.


Related Article

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.