⇥ HipHop: What you need to know

February 2, 2010
19 comments
 
⇥ Permalink

By now, unless you’re living under several hundred metres of rock,  you’ve probably heard that Facebook has released HipHop for PHP, a tool that compiles PHP into C++ with some interesting claims of speed improvement. The thickness of unawareness-inducing rock may have to be lower to know that php|a and BP have announced our full support for the project with a number of initiatives that we’re going to roll out over the next few months.

I have known about this project for a little while—Facebook was kind enough to invite me, along with a few other community members, to their office for a demo a few weeks ago. They gave me a copy of HipHop to try out, and I have been playing with it for the last few days.

What it is

First, a few random notes on how HipHop works. Haiping has done a great job of providing in-depth coverage in his post on the FB blog, so here are the CliffNotes:

  • HipHop transforms PHP into C++ code, which can then be compiled into a self-contained executable. The tool supports a large percentage of the current PHP 5.2 spec, with some obvious exceptions, like eval().
  • The tool attempts to find the maximum level of optimization possible for a given scenario using its own static analysis tool. For example, if it detects that all operations on a given variable are homogenous in type (e.g.: they are all integers), then it uses the corresponding C++ data type to provide maximum speed and memory enhancement. Where this is not possible, it implements its own variant type, equivalent to a zval.
  • HipHop doesn’t currently have its own PHP runtime—nor is it based on Zend Engine. It compiles everything to C++ and uses its own set of C++ library to provide the necessary support.
  • Once compiled, HipHop provides its own web server (a CLI interface is also available). It does not use (or require) Apache or any other server. Of course, this doesn’t preclude you from running one or more HipHop projects against separate ports on the same machine and then use Apache (or Squid, or any other server) to reverse proxy to them.
  • HipHop doesn’t currently support Windows (though, personally, I’d be surprised if that didn’t eventually change—it just so happens that FB built for the environment they use internally).
  • The entire tool is intended to be a drop-in replacement for the PHP runtime—as long as you do not use any functionality that it doesn’t support, you should be able to compile your existing site and run it.
  • Facebook is using HipHop in production to handle 90% of their traffic.

What it’s going to do

HipHop has the potential to be an incredibly disruptive product in the PHP landscape. If your company runs a PHP application that requires more than two servers (you’ll want two just for redundancy), you have no reason not to explore using HipHop. If Facebook’s claim of a 50% reduction in CPU usage means you could, potentially, get rid of 1/2 of your PHP machines with a minimum of investment. You don’t need to be Facebook to draw a huge advantage from this technology. Perhaps this one-to-one reduction is not apt, but even 40% or 30%—much more realistic—is major, and a truckload and a half more than any other existing PHP-related product can offer at this point.

Clearly, this argument can be flipped around: you have every incentive to make sure that your application runs with HipHop—which could give Facebook a unique opportunity to exert significant control over the way PHP evolves.

You might, at this point, think that this is not the first attempt at a PHP compiler—in fact, there are other compilers commercially available. Heck, even I wrote my own experimental compiler several years ago (in fact, I had a discussion about my experience with some of the Facebook team members about this a while back, presumably while they were researching HipHop)—and that ultimately it won’t make a difference.

But HipHop is neither experimental nor unproven, and it’s free; it is used, in production, by the second-largest site on the Internet—and make no mistake about it, there is no smoke-in-your-eyes (not to mention other body parts) sleight of hand on Facebook’s behalf; their site is written in PHP by PHP developers, without the help of large numbers of custom extensions. In fact, their goal is precisely to allow their developers to continue using PHP—which they consider the nimblest web development environment—without compromising their ability to grow at the current pace in a financially responsible way.

If you think about it, that makes a lot of sense from a business perspective: PHP is simple, flexible and easy; with HipHop as a drop-in compiler, FB can achieve an immense immediate benefit with essentially no disruption to their operations. The question now becomes: shouldn’t everybody else?

Reblog this post [with Zemanta]