Performance Comparison between PHP7.0.11 and PHP5.6.23 on Two VPS



I recently purchased a $5 VPS from Vultr and what I get is 1 core (2.4GHz), 740MB RAM and 15GB SSD. It is the basic (minimal) specs and nothing compared to my luxury VPS from QuickHostUK, where my VPS is 6 cores (2.4GHz), 3GB RAM, 50GB SSD.

I have legacy PHP code and that is why I hold on on upgrading to Ubuntu 16.04 and PHP7.x but suddenly I thought it will be interesting to compare the performance between PHP7.0 (Ubuntu 16.04) and PHP5.6 (Ubuntu 14.04).

PHP Benchmark Code

The following is the code that translated from this post. It is to compute the prime numbers up to N.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
define('N', 1000000);
 
$Primes = array();
$Primes[0] = false;
$Primes[1] = false;
for ($i = 2; $i <= N; $i ++) {
  $Primes[$i] = true;
}    
 
$M = sqrt(N);
for ($j = 2; $j <= $M; $j ++) {
  if ($Primes[$j]) {
    $i = $j * $j;
    while ($i <= N) {
      $Primes[$i] = false;
      $i += $j;
    }
  }
}
 
$s = '';
for ($i = 0; $i < N; $i ++) {
  if ($Primes[$i]) {
    $s .= $i . " ";
  }
}
 
echo md5($s);
define('N', 1000000);

$Primes = array();
$Primes[0] = false;
$Primes[1] = false;
for ($i = 2; $i <= N; $i ++) {
  $Primes[$i] = true;
}    

$M = sqrt(N);
for ($j = 2; $j <= $M; $j ++) {
  if ($Primes[$j]) {
    $i = $j * $j;
    while ($i <= N) {
      $Primes[$i] = false;
      $i += $j;
    }
  }
}

$s = '';
for ($i = 0; $i < N; $i ++) {
  if ($Primes[$i]) {
    $s .= $i . " ";
  }
}

echo md5($s);

VPS Comparisons

Here is the PHP version from Vultr VPS.

php7.0 Performance Comparison between PHP7.0.11 and PHP5.6.23 on Two VPS implementation php

PHP 7.0.11-1+deb.sury.org~xenial+1 (cli) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
with Zend OPcache v7.0.11-1+deb.sury.org~xenial+1, Copyright (c) 1999-2016, by Zend Technologies

Here is the PHP version from QuickhostUK VPS.

php5.6 Performance Comparison between PHP7.0.11 and PHP5.6.23 on Two VPS implementation php

root@uploadbeta:/var/www/test# php –version
PHP 5.6.23-1+deprecated+dontuse+deb.sury.org~trusty+1 (cli)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies

PHP Code Execution Performance between 5.6 and 7.0

Now, let’s run the benchmark php script to see how long it takes on both VPS (remember PHP7.0 VPS has only 1 core and 740RAM but PHP5.6 VPS has 6 cores and 3GB RAM).

php5.6-performance Performance Comparison between PHP7.0.11 and PHP5.6.23 on Two VPS implementation php

php5-6-performance

php7.0-performance Performance Comparison between PHP7.0.11 and PHP5.6.23 on Two VPS implementation php

php7-0-performance

That surprised me a little bit!

PHP7.0 outperforms the PHP5.6 up to almost 12 times faster! Click To Tweet

even the PHP5.6 is possible to use more cores and more RAM. Both CPUs are the same clock speed (2.4 GHz). I have run the code multiple times to confirm the consistency of the comparisons.

Update: I have upgraded QuickHostUK to Ubuntu 16.04 + PHP 7.08 and run the test on the same Instance, here is the result:

1
2
3
real    0m1.191s
user    0m0.464s
sys     0m0.726s
real    0m1.191s
user    0m0.464s
sys     0m0.726s

Still pretty good improvements with PHP7 (around 3 times faster). However there is a chance that PHP7.0.11 gives more speedup than PHP7.0.8.

This is just tiny simple example (with majorly the integer computation), not to mention some other complex and time-consuming code in modern websites e.g. WordPress. If you have not used PHP7.x yet, start using it then!

PHP-7-Features-that-will-woo-every-PHP-fan Performance Comparison between PHP7.0.11 and PHP5.6.23 on Two VPS implementation php

php-7-features-that-will-woo-every-php-fan

–EOF (Coding For Speed) —

GD Star Rating
loading...
739 words Last Post: Which is Faster? VBScript or JScript on WSH - A Performance Comparison using Sieve of Eratosthenes
Next Post: Integer Performance Comparison for C++, C#, Delphi

The Permanent URL is: Performance Comparison between PHP7.0.11 and PHP5.6.23 on Two VPS (AMP Version)

Leave a Reply