⇥ HipHop: What you need to know
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]](http://img.zemanta.com/reblog_e.png?x-id=168f0eaf-9081-42c0-b324-70b826b06263)
Comments
This definitely has a strong potential of fragmenting the php community into 2 camps, if that were to happen I can see further forks breaking off from the “official” php interpreter. Interestingly enough facebook may unintentionally do a lot of harm to PHP.
Hey Marco,
thanks for the writeup, it answered a good lot of questions I still had.
@Shawn: I don’t think / hope so. That wouldn’t be in anyone’s interest, so I highly doubt that facebook, who are the commercial overlords of this fancy little software after all, will let that happen.
[...] really excited to explore HipHop as it claims to be the bee’s knees, and there’s been a lot of hype over it since the announcement. HipHop claims to improve PHP’s performance by fifty [...]
Thanks for the excellent writeup Marco – put some of the detail around HipHop that I needed to know!
I don’t think it will fragment the community – if anything it has the ability to grow the PHP developer base, companies that have turned away from PHP in the past because of script vs. compiled languages (.NET/Java) now have another choice.
It seems the project is very mature, even before public release – it’s running 90% of Facebook! – it can only improve once the community bend it/commit/update it on Github.
An exciting year for PHP 2010 could very well be!
[...] http://blog.tabini.ca/2010/02/hiphop-what-you-need-to-know/ [...]
Running its own HTTP server is the game-changer for me.
[...] Thoughts on HipHop To paraphrase Marco Tabini if you work with PHP you must be doing so in a pretty deep cave to have not heard of HipHop for PHP [...]
I’m very interested in hearing more about HipHop, and I can certainly see where it is of great importance to the facebook’s and yahoo’s of the world.
I’m wondering though how useful it’s going to be to the 90th percentile though. In practice scaling PHP is rarely about PHP not having enough CPU. It’s about database and other IO scaling. In fact, most shops I’ve worked, when going beyond the ’2 machines’ as you mention Marco, are doing so not because of CPU restrictions, but because of maxing out the network IO of the machine, or needing more memory.
Now, if HipHop also reduces the memory footprint, that’s interesting. Or if HipHop’s built-in webserver happens to be more efficient in some ways than a stripped apache, that also adds intrigue.
I’ll be curious to watch the future development & adoption of this. It’s a great idea. But currently I’m just not thinking that the 90th percentile is going to have much use, if any, of this.
[...] been lots and lots of discussion regarding the Facebook “Hyper PHP” release of HipHop for PHP. [...]
Exciting stuff. If eval() is out, I wonder about unserialize, apc_fetch, memcache_get, etc… Built-in HTTPd is indeed cool.
[...] What about developer fragmentation? This definitely has a strong potential of fragmenting the php community into 2 camps, if that were to happen I can see further forks breaking off from the “official” php interpreter. Interestingly enough facebook may unintentionally do a lot of harm to PHP. —Shawn S [...]
[...] Tabini has a nice summary on what PHP need to know about HipHop. However, people I’ve talked to have had several [...]
Everyone seems to forget that they also made it Thread Safe! This means that yes, HipHop also reduces memory usage, since threads use shared memory. The lead dev also mentioned something about since it is threaded, database connections are much faster.
[...] Marco Tabini [...]
Thanks for the very interesting article. HipHop seems really interesting, we have had to switch to lighttpd and xcache to achieve huge performance benefits for our objectCMS framework which is now faster that wordpress, joomla and drupal. I am wondering how hiphop compares to lighttpd and xCache, does anyone know when hiphop is going to be released to the public.
Sounds great. As a php developer I see apps constantly growing in complexity and performance suffering the consequences. Maybe this can reverse the trend?
[...] HipHop: What you need to know [...]
[...] analytics on HipHop from Marco Tabini, Ilia [...]
[...] Marco’s blog post [...]