This article is originally from abroad this article: PHP performance Evolution 2016, thanks to the high-availability architecture of the public number translated into the Chinese version, here is reproduced in the highly available architecture translated articles from PHP 5 to PHP 7 performance full evaluation (including the unpublished JIT version of PHP 8 contrast), A slightly adjusted format.
Introduction: PHP is the most commonly used language in WEB development, and each large version of the update brings many new features and performance improvements. In particular, the release of PHP 7.0 brings a leap in PHP performance. The author of this article performs a benchmark of CPU performance for each PHP version and brings the next large version of PHP to the message. The Chinese version of this article is translated by a highly available architecture volunteer.
Since 1994 Rasmus Lerdorf created PHP, the PHP language has undergone many improvements, with performance being one of the key criteria that developers consider when evaluating a new version.
Read this article to learn about the performance gains from PHP 5 to 7 (including 7.1), as well as the performance of the experimental JIT branch version that is about to be added to PHP 8.Brief introduction
This article will update on time to add more information and benchmark results, including new releases that have not yet been released, to better understand the evolution of PHP performance over the years. If you have corrections or suggestions for improvement, please leave a message after the article.
Since 1994 Rasmus Lerdorf created PHP, the PHP language has undergone a fierce evolution. Although the first edition was a simple one-man-developed CGI program, Rasmus Lerdorf, Andi Gutmans and Zeev Suraski joined the development of the third version of the language and fundamentally redesigned it. Since then, the PHP Development Group has also been created and developed.
With the development of the project, due to PHP 3 's natural extensibility, PHP's capabilities in core and extension development have been booming, such as network communication, parsing, caching and database support.
The language itself is also evolving, bringing a series of improvements. This includes support for object-oriented structures such as classes, interfaces, traits, closures, and so on.
For many developers, only new features are not enough. As languages become more and more popular, the PHP community is increasingly demanding to provide better performance, scalability, and less memory usage.
The PHP development team has been working on these requirements for nearly 20 years, although the introduction of PHP 3 has greatly improved performance, but until Andi Gutmans and Zeev Suraski introduced Zend Engine and published PHP 4, PHP's performance began to become formal.
The new memory compiler and actuator model introduced in 2000 greatly improved PHP performance (5 times or even 10 times times) and was first used by formal WEB applications and sites. We can say that the results of PHP today are far beyond anyone's expectations when the PHP project was born.
The boom in PHP has added to the desire to improve performance. Fortunately, the model designed in Zend Engine provides a good basis for continuous optimization of performance.
While PHP 5.0 does not deliver substantial performance gains, and in some cases is even slower than PHP4, a team led by Dmitry Stogov has been continuously refining the language in subsequent releases with the help of the community, and in most cases, in the case of PHP 5.6, performance has increased by 1 . between 5x and 3x.
In December 2015, PHP 7.0 made a major breakthrough. The 7.1 release also brought a series of enhancements in December 2016.PHP 8 Performance Outlook
This is a promising version, currently under development, led by Zend's Dmitry stogov. Although it is based on the PHP 7.1 version, but the actual version number has not yet been defined, so this article says this version is under the "Experiment JIT" branch.
Critical function JIT (just-in-time) compilation is a technique for translating code into another bytecode, such as the local code that runs its machine CPU. JIT can make programs run faster.
This article covers the results of several benchmarks, from the first version of PHP 5 to the Experimental JIT branch version of PHP, and the version performance prior to PHP 5 is not covered in this article.
In writing this article, it is difficult to determine if PHP 8 will have another major version, such as PHP 7.2. But it can be assumed that when PHP 8 was released, it already included the power of the current trial version of the JIT branch.PHP Performance evaluation
This article only runs baseline tests for pure CPU task scripts (tasks that do not require I/O operations such as access to files, network, or database connections).
The baseline test script used is as follows:
Benchmark scripts run only with the latest iteration of each PHP major version. Therefore, the version of the test is as follows:
Of course, I want to make sure that we run all the minor versions on the same benchmark, for example, between 5.3.0 to 5.3.29. The result is convincing: the main performance enhancements are not the minor versions, but the major version numbers, such as PHP 5.4 to PHP 5.5, or PHP 5.6 to PHP 7.
The minor version does not show any noticeable performance improvements. This means that the same script should run at the same speed, whether you use PHP 5.4.0 or PHP 5.4.45.
You can view the baseline process section, detailing the settings of the host system, how each benchmark operates, and how the timing results are interpreted.Pure CPU Benchmark test results
This section gives the benchmark test results for each PHP version.
Each datum column displays a value of 3:
The results of the pure CPU benchmark are as follows:
CPU Benchmark Test
(1) The test cannot be run on a version prior to 5.3 because it uses an object feature that has not yet been implemented.
(2) The result in this column is a bit biased, because the benchmark requires at least PHP 5.3 to run. Think of them as purely illustrative, as they cannot be compared to PHP 5.0 performance.
(3) This is a modified version of the mandelbrot.php script, it runs too fast, in 7.1.0 and the trial JIT branch does not have accurate statistical time, we run the calculation 100 times in the script instead of 1 times.
Of course, these are all purely CPU benchmarks. They do not cover all aspects of PHP performance, and they may not represent the real situation. But the results are significant enough to illustrate several aspects of the problem:
This section describes the results of the 3 pure CPU benchmark scripts. It doesn't give the same number when running a PHP application that typically performs a database or file access to a typical scenario, but I think they can represent a performance improvement that you expect for some part of the code.Performance improvements per version of PHP
PHP 5 provides significant improvements over PHP 4. Zend engine is the core of the PHP interpreter, which has been completely redesigned (Zend Engine 2), laying the groundwork for future enhancements. This article does not introduce the difference between PHP 4 and PHP 5, only a brief overview of what happens after PHP 5.0.
The following sections list the improvements in subsequent versions of PHP. Please note that only changes that affect PHP core are listed here. For a more complete description, see the Change Log for PHP 5 and PHP 7.
Most of the improvements listed below are related to Zend Engine:
PHP 8/Next Generation experimental JIT Branch edition
Benchmarking is different than simply running a Unix time command to measure the execution of a script. That's why I went through the following steps:Configuring the System
First I set up a dedicated system with the following characteristics:
Before you build the full release, run the configuration script with the following options:
Note that some of the above options need to be disabled or replaced when compiling older versions, and not all extensions are available or can be compiled.Run benchmark Tests
Each benchmark is run using the PHP CLI dedicated script, which follows these steps:
Use the Microtime () function to get the script execution time from the inside. After this modification, the baseline script will look like this:
Perform 2 runs to ensure that both the PHP executable and the benchmark script contents are in the operating system cache
Run the script 5 times and extract the minimum, maximum, and average run times, such as script reports. This article only shows the average run time, which is called "Script run Time".
The php.ini file looks like this:
Use the Unix time command to clock, and the output looks like this:
The first value, real: is the time between the start of the command and the termination (when you return to the shell prompt).
The second value, User: Describes the time spent in user mode (in our case, this is the time spent in the PHP executable file).
Last value sys: Describes the time spent in the operating system (kernel) call. This value should be minimal, but if your code accesses a slow device the result will be larger. A heavy-duty operating system may also affect the values reported here.
On idle systems, the number (user + sys) should typically be very close to real. This is the case in the above example: User + sys = 1.956s,real is 1.960s. The 0.004s difference is not part of the current process: it simply means the extra time that the operating system takes to perform the task, such as scheduling.
The same script executes on a heavily loaded system, compiling 3 different versions of PHP in parallel:
Here I see clearly that the heavy load on the system itself has a significant impact on the time spent (perhaps in system time).
That's why I keep an extra value in this benchmark, operating system overhead, which is the difference between the time of the call and (user + system) time.
During the pure CPU benchmark activity, I ensured that at more than 99% of the time, this value was strictly less than 100 milliseconds, even though the script would take a few 10 seconds to complete.Conclusion
The purpose of this article is to give you an overview of the performance of a different version of PHP, starting with 5.0, to the latest version currently being developed, using a known set of benchmark scripts.
It also gives you a list of performance improvements that are addressed by each successive PHP version.
This article will be updated with the release of the new PHP version, and new benchmark results will be added in the future. I would also like to add some real-world PHP applications, such as WordPress benchmark test results.
Please feel free to leave a comment if you have any questions or if you find inaccuracies. At the same time, share this article with other developers who are interested in PHP performance.
PHP Performance full evaluation from PHP5.0 to PHP7.1