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

Jul 27, 2017 pm 02:55 PM
php php7

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"
Copy after login
# 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
Copy after login

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
Copy after login
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 of this Website
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

How to automatically set permissions of unixsocket after system restart? How to automatically set permissions of unixsocket after system restart? Mar 31, 2025 pm 11:54 PM

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

PHP Program to Count Vowels in a String PHP Program to Count Vowels in a String Feb 07, 2025 pm 12:12 PM

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

Explain late static binding in PHP (static::). Explain late static binding in PHP (static::). Apr 03, 2025 am 12:04 AM

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

How do you parse and process HTML/XML in PHP? How do you parse and process HTML/XML in PHP? Feb 07, 2025 am 11:57 AM

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

Why does an error occur when installing an extension using PECL in a Docker environment? How to solve it? Why does an error occur when installing an extension using PECL in a Docker environment? How to solve it? Apr 01, 2025 pm 03:06 PM

Causes and solutions for errors when using PECL to install extensions in Docker environment When using Docker environment, we often encounter some headaches...

What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? Apr 03, 2025 am 12:03 AM

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.

PHP and Python: Comparing Two Popular Programming Languages PHP and Python: Comparing Two Popular Programming Languages Apr 14, 2025 am 12:13 AM

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

See all articles