Skip to content
paroski edited this page Jan 27, 2013 · 43 revisions

Inicio (en español)

HipHop for PHP is an open source project developed by Facebook. HipHop offers a PHP execution engine called the “HipHop Virtual Machine” (HHVM) which uses a just-in-time compilation approach to achieve superior performance. To date, Facebook has achieved more than a 6x reduction in CPU utilization for the site using HipHop as compared with Zend PHP.

For the latest news about HipHop, be sure to like our page on Facebook and check out our blog.

Why HipHop

One of the explicit design goals leading into HipHop was the ability to continue writing complex logic directly within PHP. Companies with large PHP codebases will generally rewrite their complex functionality directly as PHP extensions in either C or C++. Doing so ends up reducing the number of people who are able to work on the company’s entire codebase. By keeping this logic in PHP, Facebook is able to move fast and maintain a high number of engineers who are able to work across the entire codebase.

HHVM versus previous HipHop execution engines (HPHPc and HPHPi)

HipHop has evolved over the years. Initially it took the form of what we call “HPHPc”, which translates PHP to C++ code, then passes that to gcc to compile into one monolithic binary representing a site’s entire code tree. This worked well, giving significant performance gains, but it was awkward for deployment, and downright untenable for iterative development. After all, you use PHP in part to avoid having to recompile after every little change. Note also, that because of the need to pass through gcc, dynamic features such as eval() were simply dropped from the language.

An AST-based interpreter called “HPHPi” came shortly thereafter as an “interactive” version of HPHP. This provided much of the automatic-recompile-on-change behavior web developers expect, but it required a lot of effort to maintain another execution engine and to keep HPHPc and HPHPi consistent with each other.

HHVM was created with the intent to replace both HPHPi and HPHPc. Unlike its predecessors, HHVM does not call out to gcc (or libgcc) to build transformed source code. Instead, HHVM operates more similarly to regular PHP in that it compiles PHP scripts into bytecode (semantic representations of individual instructions) and executes those in a virtual machine environment.

Of course, if it stopped there, then HHVM would be only slightly more performant than normal PHP (due to its optimizer). Fortunately, it doesn’t. When running in production mode, there are a number of additional options which can be enabled to perform Just in Time (JIT) compilation on that bytecode turning it into native machine code.

Using this approach, a single compiler/execution engine (HHVM) can perform the high-performance work of a production engine (HPHPc) while still maintaining the flexibility of a development engine (HPHPi).

At present, HHVM outperforms HPHPc in production configurations by up to 2x (largely dependent on PHP script layout and use-case). Because of this, and the fact that it fills the need for a development environment, HHVM should be used in favor of HPHPc and HPHPi in all cases.

HPHPi has already been deprecated and support for building it removed. Support for HPHPc will be removed by early to mid 2013.

Installing pre-built packages (HHVM)

Prebuilt packages for some distributions are available as shown below:

Building the HipHop virtual machine (HHVM)

HipHop is currently under heavy development and we only actively test on the Ubuntu distribution. Building procedures should be fairly similar on other linux distros, and support for FreeBSD and Mac OS X will be coming shortly after the retirement of HPHPc.

Here are some guides for how to get HipHop VM up and running on your distro:

Building the HipHop static compiler (HPHPc)

Don’t do it. HPHPc is being phased out of use and will be removed from the HipHop distribution in a few months. You’ll still be able to get it from the git repository, of course, but HHVM will be the only version of HipHop supported in the very near future.

If you’re already using HPHPc, then you probably know how to already. If you’re just a little curious, or you forgot some element, take a look at our old Building HPHPc page.

Discussion and support

You can discuss HipHop for PHP and report bugs on our Facebook page, submit a ticket or Pull Request here on github, or check out the HipHop for PHP Blog. Note that the old Google Group HipHop developer mailing list is no longer active.

The wiki content is licensed under Creative Commons Attribution-ShareAlike License