HipHop: Facebook's PHP accelerator makes C++ code
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.