PHP Revolution: HHVM and WordPress 3.9

HipHop Virtual Machine, or HHVM for short, is taking the PHP world – you know, the programming language WordPress is written in – by storm. It is an open source PHP execution engine created by the good folks at Facebook and version 3 of it was recently released. It’s a big deal and you should care even if you’re not a developer or a system administrator.

hhvm_wp

What is HHVM?

There’s this small(ish) site that a couple of people visit every single day and spend hours there, you might have heard about it: it’s called Facebook. It is written in PHP and about four years ago when it really took off, the computational power that was needed to serve all requests was just too much because of the inefficiencies of  PHP execution engines’ that were available at that time. So they came up with the idea that instead of keep buying more server boxes, maybe they could solve the problem on a software level and created a PHP to C++ compiler named HPHPc. The original PHP code was compiled into executable binaries (sometimes file sizes reaching as much as a gigabyte!) and it was run instead of being compiled to opcodes and interpreted.

This gave about six times the performance which, to this day, is still a huge deal and one of the reasons we’re eagerly watching the development of the technology – and have been waiting for the mainstream adoption of it. Six times faster may not sound much when talking about general computer stuff, but if you look at it the following way, it might help put it in perspective for you: instead of having to buy 600 server machines to power a web service you only need 100. That’s a lot of savings just because you changed the way you run the code!

However, as you can imagine, running and maintaining separate developer and debugger versions of HipHop (called HPHPi and HPHPd, respectively), plus distributing gigabytes of executables to each machine after just a couple of changes in the code (think bug fixes), would quickly become tiresome and challenging.

This is why in 2013 Facebook decided to deprecate HPHPc but recycle the code and the experiences they gained from having it in production for at least three years and launched the HipHop Virtual Machine (HHVM). This engine converts PHP to bytecode which in turn is further converted into 64bit machine code at runtime by a just-in-time (JIT) compiler. The results? For some time now HHVM has outperformed the original HPHPc, in fact, Facebook’s production version is completely run on HHVM since Q1 2013. While benchmarks vary quite a bit (as always, they depend on a lot of factors), the results speak for themselves: 2 to 20 times performance increase when using HHVM compared to PHP-FPM.

HHVM and WordPress

As with all new software that’s set out to change the world, HHVM had quite a few problems running basically anything else other than the Facebook codes, which isn’t really a surprise, after all, it was written to do exactly that and just that!

If you tried to run WordPress with the help of HHVM either as a web server on its own (now a deprecated feature) or as a FastCGI replacement, you could have run into various problems, like having to manually edit wp-db.php as HHVM doesn’t support case-insensitive constants.

In the past year the HHVM open source project has really started to grow up and a result of countless of hours of work by its and WordPress’s developers, starting with version 3.9 of WordPress*, it will be running all WP codes without any hiccups (fingers crossed). This is the time to make the change to HHVM!

* If you didn’t follow 3.9’s development: Improve HHVM compatibility by eliminating some of our last remaining create_function() calls and making OBJECT a case sensitive constant. [27373] [27374] [27465] #14424 [27377] #27231

I’m pretty sure DevOps is an antidepressant, so why should I care?

You might not be managing your own server, but rest assured your hosting company is running some kind of a PHP processor. If it’s not HHVM or if the company is not planning to change it anytime soon, then your site’s performance will suffer. You surely don’t want that, as a one second additional page load time results in 7% decrease in conversion rates. If your site could be loaded in 1.5 seconds and you could maximize profits by not doing anything (well, except using a great hosting company cough Kinsta! :) ) you could be missing out on 7 to 21% of revenue. Can you afford to do that?

Okay you got my attention, where do I start?

By signing up for a Kinsta account and letting us know that you’d like to be HHVM’d! :) Right now I don’t know about any competitors who are offering HHVM. If you are a hosting company and have HHVM, please let us know in the comments and I’ll include you in this article! Yes, we do link to competitors. :)

If you have your own server, however, you’ll have to install it from a pre-built package or compile it yourself and set it up.

Installing or Compiling HHVM on Ubuntu

Ubuntu 14.04

wget -O - http://dl.hhvm.com/conf/hhvm.gpg.key | sudo apt-key add -
echo deb http://dl.hhvm.com/ubuntu trusty main | sudo tee /etc/apt/sources.list.d/hhvm.list
sudo apt-get update
sudo apt-get install hhvm

If you are getting segfaults

sudo apt-get install hhvm-dbg

Living on the edge (rebuilt everyday, unstable)

sudo apt-get install hhvm-nightly

Segfaults in the nightly

sudo apt-get install hhvm-nightly-dbg

Compile on Ubuntu 14.04

You must be running a 64-bit OS to compile & install HHVM.

sudo apt-get install autoconf automake binutils-dev build-essential cmake g++ git \
  libboost-dev libboost-filesystem-dev libboost-program-options-dev libboost-regex-dev \
  libboost-system-dev libboost-thread-dev libbz2-dev libc-client-dev libldap2-dev \
  libc-client2007e-dev libcap-dev libcurl4-openssl-dev libdwarf-dev libelf-dev \
  libexpat-dev libgd2-xpm-dev libgoogle-glog-dev libgoogle-perftools-dev libicu-dev \
  libjemalloc-dev libmcrypt-dev libmemcached-dev libmysqlclient-dev libncurses-dev \
  libonig-dev libpcre3-dev libreadline-dev libtbb-dev libtool libxml2-dev zlib1g-dev \
  libevent-dev libmagickwand-dev libinotifytools0-dev libiconv-hook-dev libedit-dev \
  libiberty-dev libxslt1-dev ocaml-native-compilers \
  php5-imagick

Download the latest source code:

git clone git://github.com/facebook/hhvm.git
cd hhvm
git submodule update --init --recursive
cd ..

Compile and install:

cd hhvm
cmake .
make
sudo make install

Installation Links for Other Systems

Debian Installation
Mint Installation
Fedora Installation
Other Linux Installations
Mac OS X 10.9 Mavericks (Mac OS X installation is currently EXPERIMENTAL and UNSUPPORTED.)
HHVM for Windows is not available at this time, however the team is working hard to release a compatible version later in 2014.

Using HHVM with Nginx

Add the following options to your Nginx virtual hosts file:

location ~ \.(hh|php)$ {
    fastcgi_keep_conn on;
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include        fastcgi_params;
}

For a more complete guide on how to install HHVM, Nginx and Laravel (yes, that can be exchanged for WordPress, just disregard the Laravel parts) read this great tutorial on Fideloper!

Update 21, Apr 2014:

A couple of tests with HHVM :)

(to be updated with more!)

What do you guys think, is HHVM ready for everyday usage with WordPress? Will it revolutionize PHP? Please share in the comment sections below!

Written by
Mark is a DevOps guy and head honcho at Kinsta, a performance WordPress hosting company.
  • greglgomez

    Sounds real interesting Mark!
    People are barely coming round to nginx and you guys are steaming ahead towards HHVM!
    Definitely carving your own slice of the market with vision like that. =)

    • http://www.kinsta.com/ Mark Gavalda

      Thanks Greg! I love living on the bleeding edge :), and I was waiting for a long time for HHVM and WordPress to get fully compatible. And thanks for confirming my speculation that there’s definitely business for a hosting company who doesn’t work with 5 years old technology! ;)

      • greglgomez

        I’ve been having a look at your platform, and I have a questions for you about another Nginx host I’ve come across. http://jumpstarter.io/pricing
        Now disregard the prices, I’m not really drawing up that sort of comparison, because they aren’t a managed host anyway..
        But they have an interesting approach that I haven’t seen used elsewhere, their tiers are limited by number of requests instead of page views or bandwidth..

        So my question is, what led you to choose bandwidth over pageviews or any other metric for that matter?

        • http://www.kinsta.com/ Mark Gavalda

          Sorry for the delay! Well, everyone has to come up with a couple of limits in order to be able to price packages, that can be number of visitors, pageviews, requests, etc. they’re in the same “category” though. Our price structure follows the logical rules (at least to me) of not measuring the number of visitors / pageviews because that simply doesn’t make sense to me: a pageview will only require X amount of computational power, which your setup either can or cannot handle, but bandwidth costs “a lot” (that’s subjective of course) for all hosting providers, and because MaxCDN is included in all our packages, we can tell exactly how many gigabytes a package can transfer before it becomes unprofitable for us. Of course there are situations when all these will play their role in the final pricing, but that’s not the “norm”, and we’ll always talk about custom projects and give a custom tailored quote in those cases.

  • tudoutou

    I’m a wordpress freelancer, provide HHVM or nginx hosting to my clients, I also use cdn,varnish, memcache, reddit to make their site faster, happy to know there comes more wordpress specialized hosting. I do all stuff manually to meet clients’ need, not a competitor :)

    • tudoutou

      BTW, http://www.kinsta.com/ is still showing no related content in http://getoilpainting.com/.

      • http://www.kinsta.com/ Mark Gavalda

        I’m not sure I understand what you mean?

        • tudoutou

          You did not set a default virtual host, so http://206.190.133.204 is showing content of geoilpainting.com. 9 hours ago, http://www.kinsta.com is not redirecting to kinsta.com, it shows content of http://206.190.133.204.

          • http://www.kinsta.com/ Mark Gavalda

            I’m not sure what’s with that, it’s working on our end. Maybe a glitch in the config file when reloading earlier, or a bad cache. Anyways it seems fine! Thanks though!

  • http://markjaquith.com/ Mark Jaquith

    I’ve been playing with HHVM and WordPress 3.9 today. Its performance is really impressive. But I don’t think it’s ready for production use quite yet. For instance, WordPress cookies aren’t set properly when using HHVM (you’ll be logged in the backend, but not on the front of your site). I opened a ticket for that. https://github.com/facebook/hhvm/issues/2494

    But I expect that it’ll be ready for tentative production use real soon. The great thing is that it’s super simple to switch between PHP-FPM and HHVM… just a one-line change in your Nginx config.

    • http://www.kinsta.com/ Mark Gavalda

      Thanks, Mark! Yep, I think there’s great potential in HHVM, it just has to “grow up” and receive a bit more exposure :) And exactly because of that wise decision by the HHVM team to go the FastCGI way, we can offer the choice for our clients to choose between HHVM and PHP-FPM! If something doesn’t work as it should with HHVM (I haven’t noticed the front-end cookie bug you mentioned, thanks for calling our (and the creators’) attention to that!) then they can just switch back to PHP-FPM. To be honest for the vast majority of WP based sites FPM is more than enough, especially with a good caching system in place. It’s the high traffic sites and the modern web apps built on WP that should do tests with HHVM and make the switch as soon as possible!

  • Mangap

    After wordpress I think better hhvm help opencart 2.0
    So it can use hhvm. Opencart 1.x is slow, and many people did not like the slow problem.

    Beside that please try to make many hosting support hhvm by default such as: host monster, host Gator, dream host, racks pace, blue host, godaddy and others.

    • David Martínez Moreno

      Hey, Mangap. Please report any issue with Opencart 2 in our issue tracker in Github, as we are prioritizing compatibility issues like that one, to be able to run the usual bundles in the industry (like WP+OC 2) purely on HHVM.

      • http://www.kinsta.com/ Mark Gavalda

        Thanks for stopping by David! It’s awesome that you guys are doing the HHVM optimization and it’s nice to see that you reach out to those who need help! Bests, Mark

        • David Martínez Moreno

          You are very welcome! :-)

  • http://chuckreynolds.us/ Chuck Reynolds

    Been using HHVM for a bit now w/ WordPress… built a custom install script for HHVM + Nginx too.. https://github.com/chuckreynolds/hhnginx
    Wondering why you went with 13.10? not lts? Anyways… 14.04 is out and solid. script works with it too.

    • http://www.kinsta.com/ Mark Gavalda

      That’s a really nice script Chuck! Thanks for sharing! Starred. :)
      Yep, I’ll have to update the guide to 14.04 now of course! :)

      So, what is your experience with HHVM and WP so far?

      • http://chuckreynolds.us/ Chuck Reynolds

        right on thanks. So far – LOVE it. We did try hhvm on a very large site we run and had to switch back to php5_fpm due to some older php dependancies with a recipe plugin and things but overall – loving HHVM :)

  • http://unicornuproar.com/ Moscato-Moe

    Your stats about how much faster hhvm is is a bit of a lie.

    Hhvm is a bit faster than php-fpm with the opcache enabled

Written by LondonKinsta Wordpress Hosting
Mark is a DevOps guy and head honcho at Kinsta, a performance WordPress hosting company.

Subscribe to our FREE newsletter and receive our favorite WordPress tips, tricks and tutorials!

We'll send you posts that will help you profit from your online business with WordPress.