Categories
PHP Engines

Next Generation PHP Engines: HHVM/PHP-5.5/PHPNG

HHVM:
In looking for an infrastructure to comput more efficiently HHPM an efficient PHP Engine was developed by Facebook . Commonly know as HipHop for PHP. HHPM is an intermediate bytecode language which translate PHP to native code through JIT(Just In time Compiler).PHP is simple to learn, read, write, and debug.Through HHPM CPU usage can be reduced which results in less serverGenerators,less global warming. This project of Facebook had a great impact in scaling PHP language. Now facebook is using HHVM as its software development.

A pictorial view of how HHVM works.

 

hhvm working process

 


Why HHVM ?

Enhances Performance by 9x times.
Precise destruction semantics must be relaxed.
Less File size,reduced no of servers.

PHP-5.5

With new host of functionalities, features and fixes PHP-5.5 was released.The best of it is it has no impact on the existing code. Some of its new features.

#Generators:

Here a new keyword “yield” was introduced.Like a function generator also returns value but multiple number of values. Hence coding complexity and size reduces.A small example to make it more clear.

Generators
// define a simple range generator
function generateRange($start, $end, $step = 1) {
    for ($i = $start; $i < $end; $i += $step) {
        // yield one result at a time
        yield $i;
    }
}
 
foreach (generateRange(0, 1000000) as $number) {
    echo $number;
}

 

Password Hashing

It is a new approach to handle passwords. This newly added API is easier to use,manage, hase passwords Previously crypt() was used by developers for the same function. The functions of password hashing are:

1.password_hash() :Creates password hase.

2.password_verify() :Verifies the password matching the hase.

1.password_hash() :
string password_hash ( string $password , integer $algo [, array $options ] )
2.password_verify()
boolean password_verify ( string $password , string $hash )
1. password_hash():
$hash = password_hash($password, PASSWORD_DEFAULT);

2. password_verify():

if (password_verify($password, $hash)) {
/* Valid password */
}
else {
/* Invalid password */
}

#Finally:

Finally “Finally” keyword has been introduced in php 5.5.The much awaited exception handling has been resolved.It aviods repetation of codes within try and catch block..A small example with and without finally.

Without finally block
function doSomething() {

$resource = createResource();

try {

$result = useResource($resource);

}

catch (Exception $e) {

releaseResource($resource);

log($e->getMessage());

throw $e;

}

releaseResource($resource);

return $result;

}

 

With finally block

 

function doSomething() {

$resource = createResource();

try {

$result = useResource($resource);

return $result;

}

catch (Exception $e) {

log($e->getMessage());

throw $e;

}

finally {

releaseResource($resource);

}

}

PHPNG:

PHPNG takes PHP to a new level with high performance,efficiency and memory usage.Still with its undetermined future PHPNG is in its alpha development stage. Dmitry Stogov of Zend has been significantly working on it for its better performance, better memory management. and include JIT compiler on it. PHPNG wll have an advantage on number of server worldwide as lke HHVM.

Low Level Virtual Machine(LLVM) is already a proposal for Zend Engines(open source scripting engine that interprets the PHP programming language) just like JIT.

As it is in its experimental version plenty of works are yet to be done before release of its stable one.Expectations are always high. Hopefully we can expect it in PHP 6 or PHP 7. The focus behind PHPNG is to leave behind the much famous HHVM. Certainly PHPNG is on its evolution stage but it has a lot to catch up to match up with HHVM.