PHP is one of the most popular scripting languages used for web development. The latest version of PHP, PHP 7 is a new version of the language that is been optimized for fast performance. However, PHP has a rival in HHVM (Hip Hop Virtual Machine) — a virtual tool that executes PHP code. The competition between these two options is heating up, so let’s take a look at the performance that each can offer.
What is HHVM?
In 2008, Facebook started working on a tool to convert PHP script into C++ so it could be compiled and executed on web servers. The aim was to conserve server resources, an important goal, as Facebook’s user base was growing rapidly. In this sense, the project was a success; it allowed the server to accommodate between five and six times more traffic than it had managed before.
Fast-forward a couple years to 2010. Facebook’s server needs had grown even more, placing it in a position to require another innovation to allow it to operate more efficiently. In response to this demand, Facebook developed the Hip Hop Virtual Machine (HHVM).
HHVM uses Just-In-Time (JIT) compilation to convert PHP code into a type of bytecode. It then converts this bytecode into machine code and optimizes it so that it runs as quickly as possible.
What is PHP 7?
PHP 7 is the PHP community’s response to HHVM. Early announcements of the launch of PHP 7 claimed that it would offer better than 100 percent performance improvements over the previous version of the language, PHP 5.
You might be wondering why PHP skipped version 6. The answer is that development on PHP 6 began in 2005, but it went on so long and ran into so many problems that PHP 6 had developed a bad reputation long before it was ready for release. As a result, the PHP community decided to skip the name PHP 6 and go straight to PHP 7 for the new working version of the language.
The real question is not how PHP 7 compares to PHP 5, as it is pretty clear that PHP 7 offers speedier performance. Instead, the consideration is how PHP 7 compares to HHVM. Many experts have conducted tests on the two ways of handling PHP code, which have revealed some interesting results.
PHP 7 vs. HHVM: Similarities and Differences
Before answering the “which is better” question, let’s take a look at the key differences between PHP 7 and HHVM, as well as the ways in which they are similar.
Code Interpretation
The fundamental difference between PHP 7 and HHVM is the way in which each one interprets PHP code. PHP 7 uses the standard PHP interpreter, free software that is available for anyone to use, to directly interpret and execute PHP code on the server. This generates HTML code, which is then sent to the client. The client then displays the desired content to the web user.
In contrast, the Hip Hop Virtual Machine first converts PHP code into Hip Hop bytecode. This code is then translated into machine code and executed. Some optimization takes place during this translation, ironing out inefficiencies in PHP code with the aim of delivering faster performance.
Writing Code
Both the PHP interpreter and HHVM take PHP code and execute it. Therefore, the process of writing the code is pretty much the same in each case. However, if you want to use HHVM, you need to install it on your server and then call it using the hhvm command on the command line.
Benchmark Testing
HHVM has offered much faster performance than previous versions of PHP. However, recent benchmark tests suggest that PHP 7 is slightly faster than HHVM, at least in some situations. Let’s take a look at the results of somebenchmark testing conducted by Kinsta.
WordPress: Running on WordPress 4.1.1, PHP 7 allows more than twice as many requests to be executed per second as PHP 5.6. However, it still doesn’t process quite as many as HHVM 3.6.1, which executed 624 requests per second in the test compared to just 604 executed each second by PHP 7.
Drupal: PHP 7 offers a distinct advantage over HHVM for Drupal users. PHP 7 can handle 37 percent more server requests per second compared to HHVM on Drupal 8.
Which Companies Use HHVM?
In addition to Facebook, which developed HHVM, many other businesses have adopted this solution to running PHP applications on their own servers. These include Wikimedia and the e-commerce site Etsy.
Wikimedia: Wikimedia hosts a huge range of educational content, including the famous Wikipedia online encyclopedia. Attracting nearly half a billion Internet users each month, Wikimedia needs to optimize server performance to cope with its high level of demand. HHVM poses a significant advantage over PHP in that it can load multiple SPU cores simultaneously whereas PHP is a single-threaded language that can’t be parallelized. According to Wikimedia, deploying HHVM shrank CPU load from 50 to just 10 percent, halved the mean time taken to respond to users submitting edits and reduced the average page load time from 1.3 seconds to just 0.9 seconds.
Etsy: With 54 million users, Etsy’s servers also face significant demands. Etsy engineers compared HHVM to PHP 5.4 and found that HHVM could cope with up to 280 server requests per second whereas the response time of PHP 5.4 started to dramatically increase once the number of requests grew beyond 190 per second.
What Does the Future Hold for PHP 7 and HHVM?
PHP 7 is due for stable release in November 2015. Therefore, companies are not yet using the new language, but promising benchmark test results of the performance of the beta version of PHP 7 could tempt more companies to adopt the new version of the language.
The future looks bright for PHP 7, but what about HHVM? It is likely that it is far from dead. Many businesses are already using HHVM to increase performance on their sites. The transition between PHP and HHVM is not instantaneous. It took Etsy more than six months to complete the transition. With the speed benefits of PHP 7 compared to HHVM being only very slight, it is unlikely that businesses will rush to switch back to PHP.
Facebook is continuing to develop HHVM. It has recently announced support for Mac OS X, making the technology accessible for developers who prefer to work in the Apple development environment. HHVM developers are convinced that HHVM is still faster than PHP 7 in many situations, including with WordPress.
Why Does the HHVM vs. PHP 7 Competition Matter to PHP Shop Owners?
As an online store owner, you need to make your decision on whether to use PHP 7 or HHVM based on the platform that hosts your shop. For example, if your site is built using WordPress, take a look at benchmark tests for HHVM and PHP 7 to find out how the latest release of each one performs. You want to choose the solution that can offer the biggest reduction in page load times, server response times and CPU usage.
Reasons to Choose HHVM
HHVM uses dynamic translation to deliver faster performance in many situations, including on WordPress.
HHVM uses less memory to process each request in cases where it faces a very large number of requests.
HHVM developers are steadily increasing the number of PHP code bases that the engine can run. It can already run the latest version of WordPress, along with many other common PHP frameworks and applications.
HHVM is open source. Even though HHVM has been developed by Facebook, it is open source, which means the source code is available to anyone who wants to use or alter it.
Reasons to Choose PHP 7
PHP 7 performs faster than HHVM in some situations, including when running on Drupal 8.
Using PHP 7 doesn’t require you to install or setup HHVM.
Code written in PHP 5 should work as expected after a transition to PHP 7, although some features of PHP 4 code are no longer supported in the new release. In practice, this means that any code created in the last decade is probably ready for the transition to PHP 7.
PHP 7 is developed by the PHP community, a group with a long-standing reputation for creating stable and reliable PHP releases.
HHVM vs. PHP 7: Make Your Choice
Don’t agonize for too long over the decision. Kinsta recommends that online businesses choose quickly between PHP 7 and HHVM. The sooner you make your decision, the sooner you can begin to implement the solution, allowing you to optimize your website performance. A poorly performing website can cause your reputation to suffer, which can be difficult to reverse.
Both HHVM and PHP 7 offer significant benefits compared to older versions of PHP. Make your choice and start the process of switching your site to the new system as soon as possible.