Skip to content
facebook edited this page Sep 13, 2010 · 29 revisions

HipHop for PHP transforms PHP source code into highly optimized C++. It was developed by Facebook and released as open source in early 2010.

Unlike previous similar projects, HipHop transforms your PHP source code and then uses an existing C++ compiler (g++) to build binary files. HipHop executes the source code in a semantically equivalent manner and sacrifices some rarely used features – such as eval() – in exchange for performance.

Facebook sees about a 50% reduction in CPU usage when serving equal amounts of web traffic when compared to Apache and PHP. Facebook’s API tier is able to serve twice the traffic using 30% less CPU.

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.

HipHop is not the right solution for everyone deploying PHP. We think it will be useful to companies running very large PHP infrastructures who do not wish to rewrite complex logic within C or C++.

Using HipHop

checkout and build instructions

git clone git://github.com/facebook/hiphop-php.git

HipHop currently supports PHP version 5.2 and will be updated to support 5.3. The software is open source and we hope that it’s useful to many companies around the World.

You can learn more on Building and installing.

Developing with HipHop

As a developer, HipHop also ships with an experimental interpretor (HPHPi) so that you do not need to compile your PHP source code during development and testing. Running the following commands will cause a web server to be started on port 8080 which serves the PHP content within the current directory.

hphpi -m server -p 8080
curl http://localhost:8080/

HipHop removes certain rarely used language features from PHP in exchange for performance. These include:

  1. eval
  2. create_function
  3. preg_replace() when using the /e modifier
  4. Order-dependent symbol lookups, e.g.
    if (function_exists(‘foo’)) { print ‘foo missing’; } function foo() { }

See Running HipHop to learn more about compiling your source code.

Discussion and support

You can discuss HipHop for PHP and report bugs on the HipHop developer mailing list (or feel free to submit a Pull Request).