PHP 7 installation experience, upgrade PHP with caution

Source: Internet
Author: User
Tags hhvm website server vps drupal vps server
PHP 7 installation experience, upgrade PHP with caution 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:


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 HugeAnonHugePages:    106496 kBHugePages_Total:     512HugePages_Free:      504HugePages_Rsvd:       27HugePages_Surp:        0Hugepagesize:       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:
  • 2. 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 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

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: Php memcache extensions are available: and 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.


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: 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.