In association with heise online

03 February 2010, 12:44

HipHop: Facebook's PHP accelerator makes C++ code

  • Twitter
  • Facebook
  • submit to slashdot
  • StumbleUpon
  • submit to reddit

HipHop PHP Logo Developers at Facebook have announced HipHop, a source code translator that converts PHP 5.2 code into C++, ready for compilation into machine code using the GNU g++ compiler. Haiping Zhao, one of the developers of HipHop, reports that by using the translator on Facebook's PHP code, they have reduced CPU utilisation by an average of 50%. Facebook began using the Hiphop technology six months ago and it is currently used to handle 90% of Facebook's web traffic.

PHP is a scripting language which, like Perl, Python and Ruby, can boost developer productivity. But, like other scripting languages, it is not efficient when it comes to CPU and memory utilisation. For Facebook, there was a need to optimise performance as they serve over 400 billion PHP based page views a month and so, two years ago, it launched the HipHop project.

Zhao notes that HipHop is not a compiler, but a code transformation technique. It takes PHP code and performs static analysis to identify declarations and dependencies and a type analysis to work out which C++ variable types are appropriate to map to PHP variables. Using that information, it then proceeds to convert the code from PHP to C++ with a "for the most part" direct correspondence between PHP statements and the generated C++ code. Some PHP functions have been sacrificed for this process to work, most notably the eval() function. The resulting C++ code is then compiled using g++ to produce the final executables.

HipHop also incorporates its own web server and is currently incompatible with Apache. "In general, Apache is a great Web server, but when we were looking at how we get the next half per cent or per cent of performance, we didn't need all the features that Apache offers" said David Recordon, Facebook's open program's manager, but he hoped an open source project would be created to make HipHop work with Apache. HipHop is currently suited for large scale deployments such as Facebook and isn't suited for the more typical smaller hosted PHP systems. The developers plan to support PHP 5.3 in the future and are aiming not to split the PHP community, but rather to grow the language and over the next year make the HipHop technology easier to deploy.

The HipHop code is to be released as open source under the PHP licence and will be available on GitHub, but as of writing, the code has not appeared on the site.


Print Version | Send by email | Permalink:

  • July's Community Calendar

The H Open

The H Security

The H Developer

The H Internet Toolkit