What Facebook’s HipHop means for developers and businesses

O'Reilly PHP author Kevin Tatroe puts Facebook's PHP project in context

Facebook HipHop for PHPFacebook’s PHP overhaul, HipHop, reportedly cut CPU usage on the company’s servers by around 50 percent. You don’t have to be a programmer to understand that kind of result.

Facebook says it wants to share that efficiency — and presumably influence a few things along the way — so it’s setting HipHop loose as an open source project. I asked Kevin Tatroe, co-author of O’Reilly’s Programming PHP, to weigh in on HipHop’s functionality and its broader applications.

Mac Slocum: How will HipHop help programmers?

Kevin Tatroe: One of PHP’s greatest strengths is its expansive leniency. But for very large code bases, it can also be somewhat problematic. For example, while you can change the type of data stored in a variable mid-script, I’d wager that the vast majority of the time, it’s a mistake.

Those are the kinds of things HipHop’s analysis and type inference steps will find. For that reason, I can even see running sites through HipHop that don’t need footprint savings, just as a sanity check.

MS: How about businesses that rely on PHP. Does HipHop offer them any utility?

KT: Certainly. At its best, PHP scales very well by running on teeming hordes of cheap servers. As great as that strategy has turned out to be, running on half as many teeming hordes of cheap servers has clear benefits in deployment costs and costs to maintain.

There’s also benefits at the other end of the scale. I’ve seen more companies than I can count stick with one deployment server when they really ought to be scaling up to two or three. There’s a “leap of faith” barrier there. Companies say: “Obviously, we can’t deploy on zero servers, so one seems fine. But two? We’re just a small operation. Can’t you make your code work better?”

MS: Facebook calls HipHop a “source code transformer.” In plain terms, what is that?

KT: It takes the PHP code written by PHP programmers and converts it to C++ code, which is then compiled by g++ into machine code.

In doing so, it has to disallow certain PHP language features, like eval(). And it runs a pass to determine what type each variable in your PHP code should be in C++.

PHP does not require you to state up front what kind of data you’re going to store in a variable. It lets you change the type of data stored in a given variable willy-nilly, which is not necessarily the best idea.

MS: Facebook says HipHop reduced CPU load on its servers by about 50 percent. Any idea how it does that?

KT: Running native, compiled C++ takes less processing effort to run than PHP’s scripts via an opcode virtual machine (such as using Zend Engine). That’s because it’s skipping the virtual machine entirely.

It’s telling that Facebook didn’t mention any HipHop speed increases. It’d be surprising if there weren’t any measurable speed improvements, but their primary focus seems to be: use less cheap hardware to run the same site.

MS: How easy — or hard — do you think it will be for other companies to take advantage of HipHop?

KT: This all depends on the tools. Certainly, any organization with deployments large enough to really notice much out of this will have devs comfortable with the more traditional “write, compile, test, deploy” cycle.

PHP also attracts a large percentage of folks who’ve never had to compile anything in their lives. But these same people aren’t necessarily afraid of the command line. If the tools are simple enough that people aren’t scared off, it should be pretty simple to get a site up and running using HipHop.

Note: Kevin’s comments were condensed and edited from a longer interview.

Related

Sign up for the O'Reilly Programming Newsletter to get weekly insight from industry insiders.
topic: Web Platform
  • Greg

    Once I heard that Facebook released there HIPHOP version of PHP I immediately began thinking of using it for things like WordPress.
    I do see the point about PHP devs aren’t used to compilers; having worked with many myself they can add a layer of frustration that I think some people will not want to deal with.

  • Slapo

    It’s curious that they have announced the sources would be available on GitHub on the eve of the presentation, but the repository, http://github.com/facebook/hiphop-php, seems to be either private or it doesn’t exists – when I try to access it, I get redirected to the front page of GitHub.

  • James

    I’m wondering whether there is scope for partial compiling of application code, e.g. the Zend Framework and other libraries.

  • Cal Evans

    @slapo

    Scott Macvicar will be the one actually pushing the release. Even though he’s traveling he’s working on getting the build scripts where they can be run outside of Facebook’s environment. I know once he has them stable, they will push them to github.

    @James
    No, I asked this very same question when I was out there and the answer I received was no. (or at least, not yet.) ;)

    =C=