Getting Started with HHVM and WordPress

Share this article

Only a few months ago, HHVM (HipHop Virtual Machine) was a popular buzzword in the PHP community. Many of us were curious about this technology, especially the reports of improved performance. Previously, Zend’s PHP was the only alternative — until Facebook introduced HHVM to the world.

HHVM and WordPress

Good news, HHVM is no longer a buzzword. Many people (including myself) dislike hyped up technologies, but I’m happy to write this as a post-buzzword article.

So let’s dive in!

In this article, I’ll cover:

  1. What is HHVM?
  2. What is Hack?
  3. What is the difference compared with traditional PHP?
  4. Why is it so important that it exists today (or maybe not)?
  5. What are some benchmarks to see how HHVM differs from PHP 5 and PHP 7?

What is HHVM?

To understand what HHVM is, we first need to cover what Zend Engine is (currently we’re at version 3 with PHP 7). The best explanation on this can be found on this Wikipedia article:

The Zend Engine is the open source scripting engine that interprets the PHP programming language. It was originally developed by Andi Gutmans and Zeev Suraski while they were students at the Technion – Israel Institute of Technology. They later founded a company called Zend Technologies in Ramat Gan, Israel. The name Zend is a combination of their forenames, Zeev and Andi.

Is it the language or an interpreter? It’s a ongoing debate with every scripting language. However, let’s say that PHP the language, is abstract, it’s a blueprint for the interpreter (parser). It’s more of a philosophical debate than a real debate. HHVM is like Zend Engine, but it takes a different approach to parse and run the source code.

In the end both interpreters/parsers can (in theory) execute the same source code and provide the same output with the same side effects. HHVM takes a different approach. The team behind HHVM describes it as a Virtual Machine that uses JIT (just in time) compilation to gain more speed and flexibility than Zend’s way.

One more reason to consider HHVM is speed. Until PHP 5.* benchmarks were on HHVM’s side. I know that benchmarks are also a debated topic, but when done right, they can show some truth. Long story short, HHVM appeared superior to PHP but not as much after PHP 7. The gap started to become more blurry when PHP 7 came out. So that’s why we’ll run some benchmarks today comparing them.

HHVM is still a new, cool, and different technology than Zend. It’s totally different from a technical perspective. Some things start as an experiment and may be part of a daily toolbox for some developers. Did I mention that it’s baked from Facebook and that they also use it in production (although not sure which parts of Facebook). HHVM was built from a real problem that Facebook had – speed (plus some other complicated problems that most developers might never run into).

HHVM also supports Hack. Hack is a programming language for HHVM. However, isn’t PHP the language that HHVM parses? Yes, but there’s also Hack. Basically Hack is PHP plus some other features that are not currently part of PHP or not planned in the near future. So when you write PHP, HHVM can parse and execute it, but you can also use Hack which is PHP with some additional stuff. It’s your choice. But don’t forget that Hack is not 100% compatible with PHP. The specific Hack features don’t work on Zend Engine, they only work on HHVM.

Setting up HHVM and WordPress on Docker

I didn’t want to make the whole article on just my setup, so that’s why I created WP_Dock (WordPress + Docker). If you want to know more on Docker and WordPress make sure to read these articles:

You can choose to install everything on your OS, but using Docker makes it easier for everyone to install on every OS. It also removes the need to install PHP, HHVM, nginx or MySQL on your desktop OS. That being said, you can follow HHVM’s own tutorial on how to install both HHVM and WordPress if you’d prefer.

First you have to download the Docker Toolbox if you haven’t already. Then download or clone this project.

git clone https://github.com/AleksanderKoko/WP_Dock wpdock

Download WordPress, copy it inside the folder and rename it to ‘app’. Navigate to inside the Docker folder, cd wpdock/docker.

By default, nginx runs php-fpm, so you’ll have to change this. On ‘docker-compose.yml’ change nginx ‘links‘ to ‘hhvm‘. It should look something like this:

nginx:
    build: ./nginx
    volumes:
        - ./../storage/logs/nginx:/var/log/nginx
        - ./../app:/var/www/app
    ports:
        - "80:80"
        - "443:443"
    links:
        - hhvm

Also in docker/nginx/config/upstream.conf change ‘php‘ to ‘hhvm‘. It should look like this:

upstream fastcgi-upstream { server hhvm:9000; }

Then execute docker-compose up -d nginx. This builds Docker containers using ‘docker-compose.yml’ as its configuration. Now you’ll know on which IP your containers can be found, make a note of that for the next step.

docker-machine ip default

Now open your browser to the IP noted above and you’ll see the WordPress installation guide. The final step is to change the WordPress database configuration. By default, the credentials are specified in docker-compose.yml. If you look at the MySQL section you’ll see:

mysql:
     build: ./mysql
     volumes:
         - ./../storage/data/mysql:/var/lib/mysql
         - ./../storage/logs/mysql:/var/log/mysql
     ports:
         - "3306:3306"
     environment:
         MYSQL_DATABASE: databasename
         MYSQL_USER: username
         MYSQL_PASSWORD: secret
         MYSQL_ROOT_PASSWORD: root

If you want to change the database name, username and password, change these values and then:

docker-compose down
docker-compose up -d --build nginx

Note: the MySQL host should be the IP of the machine. The one that you used on the browser to see the WordPress installation.

To switch back to PHP first run docker-compose down then change the configuration back to PHP. So remove ‘hhvm‘ as nginx link and add ‘PHP‘. Also update docker/nginx/configuration/upstream.conf to:

upstream fastcgi-upstream { server php:9000; }

Execute docker-compose up -d --build nginx to use PHP instead.

HHVM + WordPress Versus PHP 7 + WordPress

Now for the benchmark, these are the rules. I’ll use the base containers as they are. HHVM can also be used stand alone but I used it as fpm to make the comparison. I know that both can be configured to be more optimized but that is an article for another day. As HHVM needs a warm up to be at its full potential, I should make some requests first, for the HHVM to compile its stuff (we’ll do the same for PHP to make things more even). For the benchmark we’ll use Apache Bench (ab). Check their docs for installation or how to use it if you want to run benchmarks on your machine. Also, Bruno Skvorc has an excellent article on Apache Bench to help get you started.

My bench command is: ab -n 500 -c 100 http://192.168.99.100. In total there are 500 requests with 100 concurrent requests.

The PHP Results

PHP results

The HHVM Results

HHVM results

79 seconds vs 18 seconds sounds like a big promise, even if 79 seconds is PHP 7. But I have to admit that I haven’t optimized PHP or HHVM. Maybe HHVM is more speedy out of the box, so don’t take my word for granted – take it with a grain of salt, test it yourself. In the real world PHP 7 may be even faster than HHVM.

Some Final Tips

HHVM seems like a cool technology (that’s why I packed it on Docker). However, I have to warn you, use it with caution. Zend Engine is a mature, battle-tested tool. PHP in general is battle tested, and doesn’t suffer from hype. That doesn’t mean that you can’t experiment with it. That isn’t the only problem. With WordPress many plugins and themes may not work with HHVM. They were built on PHP, and HHVM is not 100% compatible with PHP.

Conclusion

In this article, we saw what HHVM is and how to setup WordPress with HHVM.

I see HHVM as a positive move from Facebook, not only from the Open Source perspective. In this new age of web where every language is jumping on the server-side train, competition rises. It’s not necessary to increase fragmentation, but it makes the whole scene different and innovative.

PHP itself has borrowed many things from Java, or Laravel from Ruby on Rails. Except being cool, fast and with new approach, the team behind HHVM has also pushed the team behind Zend Engine to become even better. PHP 7 was one of the best updates to hit the PHP community. As PHP itself is so coupled with Zend, competition from other teams, is a good thing. Also, a few may know that HHVM is not the only Virtual Machine in the game. Tagua VM is a new VM written with Rust. Also, their approach is different, where the main idea was to be memory safe.

Being curious, experimenting and production are different most of the time. However, if it happened that you’ve tried HHVM yourself, I want to hear from you. What are your experiences with HHVM? Have you tried to benchmark it on a real site? What (if any) problems have occurred?

Frequently Asked Questions about HHVM and WordPress

What is HHVM and how does it work with WordPress?

HHVM, or HipHop Virtual Machine, is an open-source virtual machine designed for executing programs written in Hack and PHP. It increases the performance of your WordPress site by using a just-in-time (JIT) compilation approach. This means it compiles the PHP or Hack code into machine code at runtime, leading to improved performance.

How does HHVM compare to PHP 7 in terms of performance?

HHVM was initially faster than PHP 7, but with the release of PHP 7, the performance gap has significantly reduced. PHP 7 has made significant improvements in terms of memory usage and is now considered comparable to HHVM in performance. However, the choice between the two depends on the specific needs and circumstances of your WordPress site.

Is HHVM compatible with all WordPress plugins?

While HHVM is designed to run PHP scripts, it may not be compatible with all WordPress plugins. Some plugins may not work as expected due to the differences in how HHVM and PHP handle certain functions. It’s always recommended to test all plugins and themes in a staging environment before deploying HHVM on a live site.

Why is HHVM no longer a part of WordPress core’s testing infrastructure?

WordPress decided to drop HHVM from its testing infrastructure because the improvements in PHP 7 performance meant that the benefits of using HHVM were no longer as significant. Furthermore, maintaining compatibility with both PHP and HHVM was a complex task, so the decision was made to focus on PHP 7+ for future development.

How can I install HHVM on my WordPress site?

Installing HHVM requires server-level access, so it may not be possible on all hosting platforms. The installation process involves downloading and installing the HHVM package, configuring your web server to use HHVM instead of PHP, and then restarting the server. Always ensure to backup your site before making such significant changes.

What are the potential issues I might face when running WordPress on HHVM?

While HHVM can improve performance, it may also introduce compatibility issues with some plugins and themes. Additionally, as HHVM is no longer officially supported by WordPress, future WordPress updates may not be compatible with HHVM.

Can I switch back to PHP from HHVM if needed?

Yes, you can switch back to PHP from HHVM if you encounter issues or if you’re not satisfied with the performance improvements. This usually involves reconfiguring your web server to use PHP instead of HHVM and then restarting the server.

Is HHVM suitable for all types of WordPress sites?

HHVM can provide performance benefits for high-traffic WordPress sites or sites with complex, resource-intensive operations. However, for small to medium-sized sites, the performance improvements may not be noticeable, and the potential compatibility issues might outweigh the benefits.

How does HHVM affect the loading speed of a WordPress site?

HHVM can significantly improve the loading speed of a WordPress site by executing PHP code more efficiently. However, the actual impact on loading speed can vary depending on the specific configuration of your site and server.

Are there any alternatives to HHVM for improving WordPress performance?

Yes, there are several alternatives to HHVM for improving WordPress performance. These include using a caching plugin, optimizing your database, using a content delivery network (CDN), and upgrading to a faster hosting provider. Additionally, PHP 7 and above also offer significant performance improvements over older PHP versions.

Aleksander KokoAleksander Koko
View Author

Aleksander is young developer who loves to play with the newest web technologies. In his free time, he reads about PHP, Firefox OS or experiments with a new language. Currently, his main interests are PHP design patterns, laravel, dart and cloud.

ChrisBFacebook HHVMhackhhvmPHPWordPressZendzend engine
Share this article
Read Next
Get the freshest news and resources for developers, designers and digital creators in your inbox each week
Loading form