Is PHP7 really that powerful?
It has been a year and a half since PHP7 was officially released. When it first came out, it was said to be several times faster than the old version. The speed and efficiency of various open source frameworks or systems running on PHP7 have increased several times. Anyway, whether it is the media or developers They are all fanning the flames, no, they should be full of praise. Today we will test it and see the effect.
It has been a year and a half since PHP7 was officially released. When it first came out, it was claimed to be several times faster than the old version. Various open source frameworks or systems run on PHP7 with high speed and efficiency. It has increased several times. Anyway, both the media and developers are fanning the flames. No, they should be full of praise.
I will just watch you show off quietly and say nothing.
Generally, I am the last person to upgrade mobile phone systems because I don’t want to step into the trap. After all, systems like iOS and Android will have bugs, not to mention the most hacked languages in the world.
The time has come today to see if PHP7 is as awesome as the legend says.
Install two PHP versions
http://php.net/ There is already the latest version of PHP7, you can download it yourself.
In order to test the performance of PHP5 and PHP7 (PHP6 has been abandoned, distressed 1s), I installed two php versions in different directories.
The installation process is skipped. Regardless of source code installation or package management tool installation, just remember your own path.
PHP7:
1 2 3 4 |
|
PHP5:
1 2 3 4 |
|
Environment description: In order to ensure the best test effect, this test is conducted directly in the production environment, which is closer to the real situation.
Operating system: CentOS 7.2 64-bit
Basic configuration: 1 core 1GB 1Mbps
Host brand: Tencent Cloud
Confrontation between PHP7 and PHP5
1. Pure php script test
vim test.php
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
PHP5 version test:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
PHP7 version test:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
|
passed It can be seen from the data that through pure PHP script testing, it can be seen that the performance of PHP7 has been improved by 3 to 4 times.
2.php database operation test
First we create a user table:
1 2 3 4 |
|
Insert a piece of data into the test_user table:
1 2 3 4 |
|
Create a database test script test_db.php, make sure both your PHP versions have the PDO extension installed.
1 2 3 4 5 6 7 |
|
My two PHP versions have PDO installed (do not use the php_mysql extension anymore, it is outdated, PHP7 has been completely abandoned, and mysqli is not recommended).
Next we write a script through PDO to test the performance comparison of select execution 500,000 times:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
|
PHP5 test test_db.php:
1 2 3 4 5 6 7 8 9 10 11 12 |
|
PHP7 test test_db.php:
1 2 3 4 5 6 7 8 9 |
|
This time the script executed 500,000 queries. The user execution time of the script executed by PHP7 is almost one second less than that of PHP5! It's one second less, not one millisecond.
3.PHP framework test
thinkphp
The thinkphp framework is definitely the first choice in China, choose the latest thinkphp5. I downloaded the thinkphp5.0.9 version directly from the official website.
- (1) Framework entrance test
Test under PHP5:
1 2 3 4 5 6 7 8 9 10 |
|
Test under PHP7:
1 2 3 4 5 6 7 8 9 10 11 12 |
|
at the entrance After testing, you can see that there is not much difference between PHP and PHP7, but PHP7 is still slightly faster.
- (2) Framework logic test
Reuse the logic of the first step at the framework entrance:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
|
PHP5 version:
1 2 3 4 5 6 7 8 9 10 |
|
PHP7 Version:
1 2 3 4 5 6 7 8 9 10 11 12 |
|
Using the PHP7 version in the thinkphp framework, the performance improvement is about 4 times that of the PHP5 version!
laravel
Then we test the most popular PHP artist framework.
- (1) Framework entry test
PHP5 version:
1 2 3 4 5 6 7 8 9 10 11 |
|
PHP version
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
We can see that laravel’s framework entry test is in progress , the performance difference between PHP5 and PHP7 is not big, but even the fastest 0.081s of PHP5 is slower than the slowest 0.067s of the PHP7 version. So PHP7 is still better.
- (2) Framework logic test
Try to add a little logic, just like thinkphp, reuse the test logic. First modify the laravel routing and directly call the index method of UserController:
1 |
|
Write the test logic in the index method:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
|
PHP5 version
1 2 3 4 5 6 7 8 9 10 |
|
PHP7 version
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
PHP7 performance has been improved by 3 to 4 times
Recommended learning:php video tutorial
Conclusion:
This article has a review on PHP7 and A simple comparison of PHP5 shows that the performance is indeed improved by 3 to 4 times. Whether in PHP pure scripts or in frameworks, PHP7's high-performance performance is consistent.
PHP7 is fast, PHP7 OpCache is fast, PHP7 is really awesome, a new era of PHP has arrived, use it quickly!
The above is the detailed content of Is PHP7 really that powerful?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



How to install the mongo extension in php7.0: 1. Create the mongodb user group and user; 2. Download the mongodb source code package and place the source code package in the "/usr/local/src/" directory; 3. Enter "src/" directory; 4. Unzip the source code package; 5. Create the mongodb file directory; 6. Copy the files to the "mongodb/" directory; 7. Create the mongodb configuration file and modify the configuration.

To resolve the plugin not showing installed issue in PHP 7.0: Check the plugin configuration and enable the plugin. Restart PHP to apply configuration changes. Check the plugin file permissions to make sure they are correct. Install missing dependencies to ensure the plugin functions properly. If all other steps fail, rebuild PHP. Other possible causes include incompatible plugin versions, loading the wrong version, or PHP configuration issues.

In php5, we can use the fsockopen() function to detect the TCP port. This function can be used to open a network connection and perform some network communication. But in php7, the fsockopen() function may encounter some problems, such as being unable to open the port, unable to connect to the server, etc. In order to solve this problem, we can use the socket_create() function and socket_connect() function to detect the TCP port.

Common solutions for PHP server environments include ensuring that the correct PHP version is installed and that relevant files have been copied to the module directory. Disable SELinux temporarily or permanently. Check and configure PHP.ini to ensure that necessary extensions have been added and set up correctly. Start or restart the PHP-FPM service. Check the DNS settings for resolution issues.

How to install and deploy php7.0: 1. Go to the PHP official website to download the installation version corresponding to the local system; 2. Extract the downloaded zip file to the specified directory; 3. Open the command line window and go to the "E:\php7" directory Just run the "php -v" command.

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

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

Compared with PHP7, PHP8 has some advantages and improvements in terms of performance, new features and syntax improvements, type system, error handling and extensions. However, choosing which version to use depends on your specific needs and project circumstances. Detailed introduction: 1. Performance improvement, PHP8 introduces the Just-in-Time (JIT) compiler, which can improve the execution speed of the code; 2. New features and syntax improvements, PHP8 supports the declaration of named parameters and optional parameters, making functions Calling is more flexible; anonymous classes, type declarations of properties, etc. are introduced.
