1 of 37

HHVM

@richardtape

2 of 37

3 of 37

4 of 37

“It was a high-risk, high-reward

bet. We now operate at such an

enormous scale, we have to

take enormous risks in

order to survive”

Jay Parikh, Facebook engineer

$

5 of 37

HipHop for PHP (HPHPc)

  • A PHP transpiler (a PHP whatnow?)
  • Transpiles/Translates PHP into C++
  • Then compiled into a binary
  • Then run as an executable
  • Regularly increased the speed of PHP Applications by 6 times

6 of 37

Wait. Binary? Executable? What?

  • Caveat: IANAG (it’s a bit like I am not a lawyer)

  • Normal PHP
  • <?php your_code(); ?> -> opcodes -> interpreted (i.e. non-compiled, slow)

  • HPHPc
  • <?php your_code(); ?> -> Transpiled (fast!) into C++ -> compiled into a binary -> executed

7 of 37

YOU SAID COMPILE!!

8 of 37

9 of 37

A new challenger approaches

10 of 37

Hip Hop Virtual Machine

Seriously. That’s actually what HHVM stands for.

HHVM is a “process virtual machine” using just-in-time compilation

11 of 37

YOU SAID COMPILE!!

12 of 37

13 of 37

Don’t panic!

  • The ‘just-in-time’ part before the word-we-no-longer say is key

  • It means you don’t have to do it yourself

  • And you just write your PHP as you normally would

14 of 37

Process Virtual Machine?

AKA an Application Virtual Machine. (Oh that’s much better.) Or a Managed Runtime Environment (Who makes these things up?)

In real words it means that your code is completely abstracted away from the underlying platform which in turn means the same code will give the same results, regardless of platform.

15 of 37

Hip Hop Byte Code

I promise you I’m not just making up words. Again, that’s actually it’s name.

PHP (and ‘Hack’) are converted into Hip Hop Byte Code (HHBC) which is then converted into machine code and then executed.

16 of 37

STOP USING ACRONYMS AND MADE-UP WORDS AND SHOW ME SOMETHING

17 of 37

If you can write PHP, you can use HHVM

If you can’t write PHP, you can learn Hack – a gradual typed language – and use HHVM

18 of 37

  • If you write PHP and it breaks HHVM, there’s a very good chance you’re not writing good PHP

  • HHVM supports the vast majority of the PHP language (even *gasp* eval() )

  • If you conform to the WordPress PHP Coding Standards, you’ll almost certainly have no issues whatsoever

19 of 37

"After all, facts are facts, and although we may quote one to another with a chuckle the words of the Wise Statesman, 'Lies--damned lies--and statistics,' still there are some easy figures the simplest must understand, and the astutest cannot wriggle out of.”

Leonard Henry Courtney, 1895

20 of 37

  • Performance-wise, comparing PHP 5.2.* to HHVM is, honestly, an unfair fight.

  • So if your host is still forcing you to use PHP 5.2. Change host. Literally now. Leave the room. Go do it. I won’t judge.

  • (It’s fun, nonetheless, so here’s some quick numbers on a simple hello world script)

  • PHP 5.2.17: 445 requests per second
  • HHVM 3.8.0: 890 requests per second (! 2*)

21 of 37

  • OK, let’s make this a bit more of a fair fight. Let’s go with PHP 5.6.4

  • Simple <?php echo ‘Hello world’; ?>

  • PHP 5.6.4 – RPS: 651 (a 50% + on PHP 5.2)
  • HHVM 3.8.0 – RPS: 890

  • Running default WordPress (APC Object Cached, you’re welcome PHP)
  • PHP 5.6.4 – RPS: 281 (non-cached, ootb: 41, bless)
  • HHVM 3.8.0 – RPS: 566

22 of 37

  • But Rich, PHP 7 is out soon. And that’s meant to be SUPER fast!

  • The current PHP mainline is 11% faster than PHP 5.6.4�
  • That’s pretty freaking awesome.

  • It’s still ~20% slower than HHVM which gets updated every 8 weeks. PHP 7 may probably will be out later this year

23 of 37

OK, numbers are good, but does performance REALLY matter?

24 of 37

Every -100ms = +1% in revenue (Amazon, Walmart). Case closed.

25 of 37

  • Who is using/supporting HHVM already?

  • Well, unsurprisingly, Facebook. So you can consider it battle-tested.

  • Etsy are experimenting (and it’s going well)

  • Me! *ahem*

26 of 37

Who in the WordPress managed-hosting world is supporting HHVM?

  • WPEngine
  • Pagely
  • Siteground
  • Dreamhost

27 of 37

But, what if I’m running my own good ship lollipop?

Well, calm down Shirley Temple. You’re bright eyes are almost certainly covered.

Pretty much every main Linux distro is supported

28 of 37

Q: How easy is it to set up from scratch?

A: Very. 15 minutes. If you’re using nginx or apache, the HHVM setup routine “just works” out of the box.

29 of 37

Q: How easy is it to switch from PHP-FPM?

A: Depends. But probably very. 20 minutes. The ‘hard’ part will be adjusting your existing config, but HHVM’s default config is an almost drop-in replacement.

30 of 37

What about my PHP Extensions?

https://github.com/facebook/hhvm/wiki/Extensions

A lot of commonly used extensions (most, I would say) are supported out of the box. The big one not supported ootb is pgsql but this has a third-party extension (yay open source)

I haven’t run into any extension issues, but they have an API for you to write your own:

https://github.com/facebook/hhvm/wiki/Extension-API

31 of 37

Any gotchas with WordPress-y stuff?

Yes. Sadly. But they’re becoming fewer and fewer. These 3 commits fixed a whole bunch of things:

https://core.trac.wordpress.org/ticket/27231

https://core.trac.wordpress.org/ticket/29217

https://github.com/facebook/hhvm/commit/516e149377edcd10cbb8f208a2f9545485488603

The big gotchas are now - as far as I can tell - entirely plugin/theme based (surprise!)

32 of 37

So… Plugins / Themes?

HHVM does not have 100% compatibility with PHP yet. Its aim is for parity. So, if a plugin uses some unsupported stuff then the world ends.

That being said, if it isn’t supported, it’s probably not the best code out there so may be worth considering a different option.

Basic gotcha: long-running tasks on a wp-cron seem to break things. i.e. backup plugins. *on bad hosting

33 of 37

How about Plugins / Themes?

https://wordpress.org/plugins/wordpress-backup-to-dropbox/ (long wp-crons)

https://wordpress.org/plugins/wp-all-import/ (php://filter usage … bit weird)

Can bring your site down on HHVM. Sad Panda. (But you can run PHP-FPM as a fallback…)

34 of 37

Is it ready for prime-time?

Facebook think so. But then they would, wouldn’t they?

My personal opinion;

On a small site where you control everything: yes

On a managed host where it’s controlled for you: yes

Everywhere else: it needs some serious consideration right now. But as time goes on, it becomes more and more a genuinely viable option.

35 of 37

Who are you, again?

Richard Tape, a developer at UBC – The University of British Columbia

@richardtape on Twitter

36 of 37

37 of 37