|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2018-07-02 19:06 UTC] gilperon at gmail dot com
Description:
------------
PHP 7.2 is very fast, amazingly fast. Doing very simple benchmarks (like looping thousands of times and doing some basic arithmetics) demonstrates that PHP 7.2 is easily 3x faster than PHP 5.4.16 (which is the default PHP version that comes enabled to be installed on Centos 7 using the "yum").
BUT for some strange reason doing DB queries is AT LEAST 2X slower - at least.
I booted 2 CENTOS (version 7.1) servers - identical. Then on one I installed PHP 5.4.16 and in the other I installed PHP 7.2.7 (both were running the latest version of MariaDB).
Then I created a simple database and executed the benchmarking in the TEST SCRIPT section.
I executed this code at least 5 times on each server, allowing some delay between tests. They were very clear:
PHP 7.2 took about 4.5 seconds to run PHP 5.4.16 took about 1.1 seconds to run
So what? Is there something with PHP 7.2 that I am not aware that I should be taking into account when querying db?
Test script:
---------------
<?php
include("connect.php");
$microtime = microtime(true);
for ($i=0;$i<100;$i++) {
$query = "SELECT * FROM table WHERE id = 'xxx'";
$result = mysqli_query($connection,$query);
$data = mysqli_fetch_array($result);
}
echo microtime(true) - $microtime;
?>
Expected result:
----------------
It should run AT LEAST at the same speed as PHP 5.4.16
Actual result:
--------------
It runs at least twice or 3 times as slow.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 01:00:02 2025 UTC |
I cannot reproduce such difference. You seems to have some very big table / row, as I have to increase the loop to 10000 to have 1/2 second, on a small RHEL-7.5 VM PHP Version 5.4.16 en 0.55 (using php-mysql and libmysqlclient) PHP Version 5.4.16 en 0.65 (using php-mysqlnd) PHP Version 5.5.38 en 0.66 PHP Version 5.6.36 en 0.65 PHP Version 7.0.30 en 0,67 PHP Version 7.1.19 en 0,67 PHP Version 7.2.7 en 0,69 PHP Version 7.3.0alpha2 en 0.55