The PHP development team put an end to WebMaster’s long wait, announcing the immediate availability of PHP 7. PHP 7, the next version of the world’s most popular scripting language (powering 81% of web) was finally released on 3rd December 2015.
After eight years to complete and weeks of delay in the roll-out, PHP 7 is finally available for download. Windows users can download the PHP 7 Windows binaries from here. With the latest version of PHP, there are many introduced changes, so PHP 7 is certainly not backward compatible with existing PHP 4 legacy code, though it should work seamlessly with PHP 5.x code. To check introduced changes in PHP 7, refer to the Changelog.
Major Benefits of PHP 7
PHP 7 has minimal syntax modifications and places more emphasis on performance improvement. In the past few months, a number of benchmarks were performed on PHP 7 and it was claimed that PHP 7 is almost 200% faster than its predecessor (PHP 5.x).
PHP 7 will run on the latest engine, namely PHPNG (PHP Next Generation), competing with interpreters like HHVM from Facebook. HHVM has been outperforming PHP for years, which encouraged the PHP 7 developer team to improve competency. Thanks to PHPNG, the PHP 7 core engine is now more optimized for CPU and memory.
Based on the benchmarks performed on PHP 7, the PHPNG engine halves memory and CPU utilization when compared with the latest 5.6 releases.
Here we discuss some of the most exciting new features that will be available when you upgrade to PHP 7.
PHP 7 comes with two new operators, namely the spaceship (or combined comparison operator) and the null coalesce operator.
The spaceship operator ( <=> ) is used to make your chained comparison more concise. For example:
$var1 <=> $var2
This expression is evaluated as:
-1 if $var1 is smaller than $var2,
0 if $var1 equals $var2, and
1 if $var1 is greater than $var2,
which is basically a shortcut for the following expression:
($var1 < $var2) ? -1 : (($var1 > $var2) ? 1 : 0)
The null coalesce operator ( ?? ) can be used as a shortcut for a common use case. For example, with PHP 5.x, you would do something like this:
$var1 = isset($var2) ? $var2 : "default";
The same expression can be written with null coalesce operator in PHP 7 as follows:
$var1 = $var2 ?? "default";
Scalar Type Hints
Scalar Type Hints is one of the most striking features of latest PHP version. You can use integers, floats, strings, and booleans as type hints for functions and methods. In other words, when you pass a float value to an integer parameter, Scalar Type Hints will just coerce it to integer without generating any errors or warnings. However, when strict mode is enabled, it will throw errors when the wrong type is passed as an argument.
function double(int $value)
return 2 * $value;
$var = double("8");
The above code won’t generate any errors when strict mode is disabled. Additionally, the string “8” passed as an argument will be coerced into integer inside the double function. If we enable strict mode by including the directive declare(strict_types = 1) in the very first line in the above code, only integers will be allowed to be passed to the double function.
declare(strict_types = 1);
function double(int $value)
return 2 * $value;
$var = double("8");
When strict mode is enabled, the above code will generate a Fatal error.
Return Type Hints
Return Type Hints allows you to define the return type of methods and functions. It behaves same way as scalar type hints in terms of coercion and strict mode:
function a() : bool
When the above code is executed, the returned value will be converted to bool automatically without any errors and warnings. When strict mode is enabled, a fatal error will be thrown.
HHVM vs PHP 7
HHVM is the virtual machine created by Facebook developers for executing PHP applications. In the year 2008, the Facebook team developed a tool to convert PHP script into C++ so that it could be compiled and executed on web servers. The primary goal was to lower down the server resource utilization and to accommodate five to six times more traffic than the server’s actual capacity. In order to overcome these challenges, Facebook developed the HipHop Virtual Machine (HHVM). This change increased server capacity to accommodate an increase of 500-600% in web traffic.
At this point, you may ask: “What makes HHVM so fast?”
Instead of compiling PHP code to C++, HHVM utilized the Just-In-Time (JIT) compilation to convert PHP code into intermediate bytecode. This bytecode is then further translated into x64 machine code. Now JIT compiler comes into the picture, dynamically running the translation at runtime, allowing all possible optimizations. As a result, your PHP applications’ performance will be increased dramatically.
PHP 7 or PHPNG is the true competitor and community’s response to HipHop Virtual Machine. HHVM clearly outperformed the previous versions of PHP, but recent benchmark tests suggest that PHP 7 is slightly faster than HHVM in certain situations. Let’s have a look at the results of some benchmark testing conducted by ZEND on some popular apps, such as WordPress, Magento and Drupal:
Magento HHVM 3.7 vs PHP 7
Deduced from the chart below, you can make up to 3 times as many Magento catalogue server requests on the same hardware and PHP 7 uses 30% less memory.
Magento HHVM vs PHP 7 comparison
Source : www.zend.com
WordPress HHVM 3.7 vs PHP 7
According to the results shown, there is not much difference between HHVM 3.7 and PHP 7. The most interesting fact is PHP 7 utilized just 25% of the server executions compared to those of PHP 5.6. Thus, servers with same capacity will be able to serve a higher number of users.
WordPress HHVM 3.7 vs PHP 7 comparison
Drupal HHVM 3.7 vs PHP 7
The chart indicates that PHP 7 is significantly faster than HVVM and, interestingly, Drupal 8 runs 72% faster on PHP 7 compared to PHP 5.6.
Drupal HHVM vs PHP 7 comparison
You can also refer to benchmarks performed by Rasmus Lerdorf at PHP Australia. Use the arrow keys to navigate through the slides.
What Should I Go With?
Prior to PHP 7 or PHPNG, HHVM is certainly faster than PHP-Zend packages for all PHP versions. PHP 7 has demonstrated better performance against HHVM for the majority of scripts in most benchmarks.
Large websites like Etsy and Wikimedia Foundation utilize HHVM, but it took well over six months to fully switch from the PHP-Zend package to PHP-HHVM package. In other words, switching from PHP-Zend package to PHP-HHVM package is not an overnight task. For small website owners, the transition to PHP 7 would be far easier, compared to the complex transition to HHVM, which demands more expertise.
PHP 7 Hosting by AccuWebHosting
It’s no surprise that AccuWebHosting is one of the first web hosts to offer PHP 7 Hosting. Our enthusiastic testing team long awaited the latest version of PHP. On the very next day following the PHP 7 release, the team took the opportunity to test PHP 7 on our web hosting infrastructure.
We are proud to offer PHP 7 support on both Linux Shared SSD Hosting and WordPress Hosting plans.
AccuWebHosting provides a PHP configuration plugin on Linux Shared/Reseller plans, allowing customers to set the PHP 7 version for directories and domains. Our Linux Shared SSD Hosting and WordPress Hosting customers can use the following articles to change from their older PHP version to 7:
Change PHP Version From cPanel
Support for PHP 7 on a Dedicated Server
- With a Windows-dedicated server, the AccuWebHosting team will install and configure PHP 7 on demand.
- Currently, cPanel/WHM does not support PHP 7, so it would not be possible to use PHP 7 in cPanel-dedicated servers, unless the CloudLinux Operating system is used. Once cPanel/WHM starts supporting PHP 7, it can be added via WHM EasyApache.
- Linux-dedicated server (without cPanel) customers can install and configure PHP 7 according to their requirements.
Support for PHP 7 on Windows VPS
All our Windows VPS plans support PHP 7. Windows VPS customers will need to submit a ticket to install and configure PHP 7.
Support for PHP 7 on Linux VPS
Linux VPS (without cPanel) customers can install and configure PHP 7 according to their requirements. Since cPanel does not support PHP 7, cPanel VPS customers need to wait until cPanel rolls out PHP 7 support. Once cPanel starts supporting PHP 7, it can be added via EasyApache.
Rahul is CEO at AccuWebHosting.com
. He shares his web hosting insights at AccuWebHosting blog. He mostly writes on the latest web hosting trends, WordPress, storage technologies, Windows and Linux hosting platforms.
Latest posts by Rahul Vaghasia (see all)
(Visited 255 times, 1 visits today)