Whats New in PHP7, How dose it compares to HHVM Performance and Features? ~ Hybrid Mobile Apps Development, React Native, Flutter, JavaScript, Darts, iOS, Android, NodeJS
Coding Savvy FB Twitter Google
» »

Whats New in PHP7, How dose it compares to HHVM Performance and Features?

I upgraded one of my server to PHP7 to see how my application will work with it. But personally my design has been about MVC. MVC (Model-View-Controller) is a software design pattern built around the interconnection of three main component types, in a programming language such as PHP, often with a strong focus on object-oriented programming (OOP) software paradigms. On the Other hand is Hip Hop Virtual Machine HHVM, HHVM is a virtual machine for running PHP code as well as for running the new programming language HACK it is a virtual machine based on JIT (Just-In-Time) compilation.HHVM is built by Facebook which I know will work better with the MVC design pattern all I have to do is make sure that HHVN handles the business logic of the web applications. In this post, I am going to explain my experience in running PHP7 on my server and how it compares to HHVM performance.
PHP7 is just released and the latest version of HHVM supports all the features that constitute PHP7, you can tell HHVM to support all the features of PHP7 via its configuration file. The real power of HHVM comes when you have a coding pattern that totally separates the UI of your application (CSS, HTML, Javascript, images etc) from the actual business or logic of your application (PHP) in short MVC. Facebook was built using PHP, but because of performance issues. The Facebook developers created a new language and engine called Hack and Hip Hop Virtual Machine (HHVM) respectively. The Hack language is strongly typed and compiled. The HHVM is capable of executing PHP scripts and is about 95% compatible with PHP.Last I read the Facebook developers have converted all of their internal code into Hack. Which begs the question: Why not just use Hack and HHVM? HHVM is capable of parsing your entire codebase and then generated what is called an intermediate byte code that gets executed pretty fast so long that the code base is not changed. That is a plus because it saves a lot of milliseconds from first parsing the codebase for error, before actually executing the code to fulfil a request. The byte code generated from your applications codebase are must faster to execute and are often stored somewhere in the file system. The new PHP7 comes with a new Zend engine, but still HHVM out-performs it when it comes to execution speed. You must understand that HHVM is not just a new interpreter for PHP, it can become a standalone Web Server on its own, but by default, it runs as a fast CGI at the moment. However, HHVM sucks at command line services like running a daemon in PHP, PHP5-FPM still performs better at executing php-based daemon scripts than HHVM. Even though HHVM and Hack are both open source there is virtually no support for these technologies outside of Facebook. For example most web hosting providers offer some version of PHP. You will be hard pressed to find any that support HHVM. Another example is lack of editors or IDE’s supporting the Hack language. The second argument against using Hack vs. PHP has to do with the maturity of the languages. PHP has been around almost from the time of the web’s inception and as such there are a ton of libraries and community support for PHP. Hack not so much. That is not to say that Hack is a bad language. In fact, I’d argue from a design standpoint that it is a superior language to PHP. Further, it is possible that Hack will gain momentum and become a legitimate challenger to PHP outside of Facebook. At the time of this writing that scenario seems unlikely, but IT is unpredictable (Ruby is an example of a language that came out of nowhere and quickly gained popularity).

Performance

Performance is undoubtedly the biggest reason why you should upgrade your servers as soon as a stable version is released. The core refactoring introduced by the phpng RFC makes PHP 7 as fast as (or faster than) HHVM. The official benchmarks are impressive: most real world applications running on PHP 5.6 will run at least twice as fast on PHP 7. Let see the performance of PHP with popular CMS:

Return Type Declarations

Return type declarations enable for the return type of a function, method, or closure to be specified. The following return types are supported: string, int, float, bool, array, callable, self (methods only), parent (methods only),Closure, the name of a class, and the name of an interface.
<?php
function arraysSum(array ...$arrays): array
{
return array_map(function(array $array): int {
return array_sum($array);
}, $arrays);
}
print_r(arraysSum([1,2,3], [4,5,6], [7,8,9]));
/* OutputArray( [0] => 6 [1] => 15 [2] => 24)*/
?>

Group use Declarations

This gives the ability to group multiple use declarations according to the parent namespace. This seeks to remove code verbosity when importing multiple classes, functions, or constants that come under the same namespace.
<?php
// Pre PHP 7 code
use some\namespace\ClassA;
use some\namespace\ClassB;
use some\namespace\ClassC as C;
use function some\namespace\fn_a;
use function some\namespace\fn_b;
use function some\namespace\fn_c;
use const some\namespace\ConstA;
use const some\namespace\ConstB;
use const some\namespace\ConstC;/
// PHP 7+ code
use some\namespace\{ClassA, ClassB, ClassC as C};
use function some\namespace\{fn_a, fn_b, fn_c};
use const some\namespace\{ConstA, ConstB, ConstC};
?>

Integer Division with intdiv()

The intdiv() function has been introduced to handle division where an integer is to be returned.
<?php
var_dump(intdiv(10, 3)); // int(3)
?>

Support for Array Constants in define()

The ability to define array constants was introduced in PHP 5.6 using the const keyword. This ability has now been applied to the define() function too.
<?php
define('ALLOWED_IMAGE_EXTENSIONS', ['jpg', 'jpeg', 'gif', 'png']);
?>

substr() Return Value Change

substr() will now return an empty string instead of false when the start position of the truncation is equal to the string length.
<?php
var_dump(substr('a', 1));// Pre PHP 7 resultbool(false)// PHP 7+ resultstring(0) ""
?>

Change

Loosening Reserved Word Restrictions
Uniform Variable Syntax
Exceptions in the Engine
Throwable Interface
Integer Semantics
JSON Extension Replaced with JSOND
ZPP Failure on Overflow
Fixes to foreach()'s Behaviour
Changes to list()'s Behaviour
Changes to Division by Zero Semantics
Fixes to Custom Session Handler Return Values
Deprecation of PHP 4-Style Constructors
Removal of date.timezone Warning
Removal of Alternative PHP Tags : The alternative PHP tags <% (and <%=), %>, have now been removed.
Removal of Multiple Default Blocks in Switch Statements
Removal of Redefinition of Parameters with Duplicate Names
Removal of Dead Server APIs
Removal of Hex Support in Numerical Strings
Removal of Deprecated Functionality:
All Deprecated functionality has been removed, most notably:
The original mysql extension (ext/mysql)
The ereg extension (ext/ereg)
Assigning new by reference
Scoped calls of non-static methods from an incompatible $this context (such as Foo::bar() from outside a class, where bar() is not a static method)
Was this article helpful?
Thanks! Your feedback helps us improve tutorials.

You May Also Like...

No comments:

Post a Comment