Is PHP7 so awesome (horizontal comparison of php7.1 and php5.6)
Recommended (free): PHP7
PHP7来一发
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 running on PHP7 are several times faster and more efficient. Anyway, no matter what Is it the media or developers who are fanning the flames, no, it 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:
# /usr/local/php7/bin/php -v PHP 7.1.5 (cli) (built: May 13 2017 23:36:41) ( NTS ) Copyright (c) 1997-2017 The PHP Group Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
PHP5:
# /usr/bin/php -v PHP 5.6.30 (cli) (built: Jan 19 2017 22:31:39) Copyright (c) 1997-2016 The PHP Group Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
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
Competition between PHP7 and PHP5
1. Pure php script test
##vim test.php
$arr = array();for ($i = 0; $i < 500000; $i++) { $arr[$i] = $i; } $tmp = array(); foreach ($arr as $i) { if ($i % 2 == 0) { $is_exists = array_key_exists($i, $arr); if ($is_exists) { array_push($tmp, $i); } } }
time /usr/bin/php test.php real 0m0.301s user 0m0.239s sys 0m0.050s -------------------------- time /usr/bin/php test.php real 0m0.310s user 0m0.241s sys 0m0.054s -------------------------- time /usr/bin/php test.php real 0m0.289s user 0m0.238s sys 0m0.050s
time /usr/local/php7/bin/php test.php real 0m0.087s user 0m0.063s sys 0m0.024s ------------------------------------- time /usr/local/php7/bin/php test.php real 0m0.106s user 0m0.073s sys 0m0.033s -------------------------------------- time /usr/local/php7/bin/php test.php real 0m0.083s user 0m0.061s sys 0m0.022s
2.php database operation test
First we create a user table:Table: test_user Create Table: CREATE TABLE `test_user` ( `uid` int(11) NOT NULL AUTO_INCREMENT, `name` char(100) NOT NULL DEFAULT '', PRIMARY KEY (`uid`) ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8
insert into test_user (uid,name) values (1,"dada"); MariaDB [test]> select * from test_user; +-----+------+| uid | name | +-----+------+ | 1 | dada | +-----+------+
/usr/bin/php -m|grep pdo pdo_mysql pdo_sqlite /usr/local/php7/bin/php -m|grep pdo pdo_mysql pdo_sqlite
$host = "yourHost"; $user = "yourUser"; $pass = "yourPass"; $db = "test"; $port = 3306; try { $dbh = new PDO("mysql:host=$host;dbname=$db", $user, $pass); echo "Connected<p>"; } catch (Exception $e) { echo "Unable to connect: " . $e->getMessage() ."<p>"; } $sql = "select SQL_NO_CACHE * from test_user;"; $tmp = array(); for ($i=1; $i<=500000; $i++) { $ret = $dbh->query($sql); foreach ($ret as $row) { $tmp['id'] = $row['id']; $tmp['name'] = $row['name']; } }
time /usr/bin/php test_db.php real 0m48.396s user 0m11.149s sys 0m3.998s real 0m51.447s user 0m11.800s sys 0m4.395s real 0m51.517s user 0m11.733s sys 0m4.439s
real 0m47.900suser 0m9.875s sys 0m4.130s real 0m46.977s user 0m9.760s sys 0m3.983s real 0m50.010s user 0m10.268s sys 0m4.307s
3.PHP framework test
thinkphp
- (1) Framework entrance test
time /usr/bin/php ./public/index.php real 0m0.036s user 0m0.026s sys 0m0.010s real 0m0.038s user 0m0.026s sys 0m0.012s real 0m0.041s user 0m0.032s sys 0m0.009s
time /usr/local/php7/bin/php ./public/index.php real 0m0.027s user 0m0.021s sys 0m0.005s real 0m0.027s user 0m0.018s sys 0m0.009s real 0m0.025s user 0m0.023s sys 0m0.002s
- (2) Framework logic test
- Reuse the logic of the first step at the framework entrance:
<?phpnamespace app\index\controller; class Index { public function index() { $arr = array(); for ($i = 0; $i < 500000; $i++) { $arr[$i] = $i; } $tmp = array(); foreach ($arr as $i) { if ($i % 2 == 0) { $is_exists = array_key_exists($i, $arr); if ($is_exists) { array_push($tmp, $i); } } } } }
time /usr/bin/php ./public/index.php real 0m0.538s user 0m0.463s sys 0m0.072s real 0m0.454s user 0m0.386s sys 0m0.065s real 0m0.387s user 0m0.331s sys 0m0.055s
time /usr/local/php7/bin/php ./public/index.php real 0m0.150s user 0m0.123s sys 0m0.024s real 0m0.137s user 0m0.105s sys 0m0.031s real 0m0.123s user 0m0.096s sys 0m0.026s
laravel
- (1) Framework entry test
- PHP5 version:
time /usr/bin/php ./public/index.php real 0m0.104s user 0m0.081s sys 0m0.022s real 0m0.148s user 0m0.122s sys 0m0.025s real 0m0.122s user 0m0.100s sys 0m0.021s
time /usr/local/php7/bin/php ./public/index.php real 0m0.079s user 0m0.064s sys 0m0.015s real 0m0.081s user 0m0.067s sys 0m0.014s real 0m0.067s user 0m0.054s sys 0m0.013s
- (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:
Route::get('/', 'UserController@index');
public function index() { $arr = array(); for ($i = 0; $i < 500000; $i++) { $arr[$i] = $i; } $tmp = array(); foreach ($arr as $i) { if ($i % 2 == 0) { $is_exists = array_key_exists($i, $arr); if ($is_exists) { array_push($tmp, $i); } } } }
time /usr/bin/php ./public/index.php real 0m0.510s user 0m0.377s sys 0m0.079s real 0m0.627s user 0m0.447s sys 0m0.091s real 0m0.519s user 0m0.436s sys 0m0.079s
time /usr/local/php7/bin/php ./public/index.php real 0m0.201s user 0m0.167s sys 0m0.032s real 0m0.216s user 0m0.174s sys 0m0.040s real 0m0.169s user 0m0.134s sys 0m0.034s
The above is the detailed content of Is PHP7 so awesome (horizontal comparison of php7.1 and php5.6). 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

AI Hentai Generator
Generate AI Hentai for free.

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



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.

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.

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.

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.

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.

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.

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

Local environment: redhat6.7 system. nginx1.12.1, php7.1.0, the code uses the yii2 framework problem: the local web site needs to use the elasticsearch service. When PHP uses elasticsearch built on a local server, the local load is normal. When I use AWS's elasticsearch service, the load on the local server is often too high. Check the nginx and php logs and find no exceptions. The number of concurrent connections in the system is also not high. At this time, I thought of a strace diagnostic tool that our boss told me. Debugging process: Find a php sub-process idstrace-
