HipHop for PHP
|Initial release||February 2, 2010|
|Stable release||2.2.0 / October 17, 2013|
|Written in||C++, C, PHP|
|License||Free software (PHP License)|
|As of||May 2013|
HipHop for PHP (shortened as HipHop) describes a series of PHP execution engines and improvements created by Facebook. The original motivation of HipHop was to save resources on Facebook servers, given the large PHP codebase of facebook.com. As development of HipHop progressed, it was realized that HipHop could substantially increase the speed of PHP applications in general. Increases in web page generation throughput by factors of up to 6 have been observed over Zend PHP. A stated goal of HipHop is to provide a high level of compatibility for Zend PHP, where most Zend-based PHP programs run unmodified on HipHop. HipHop was originally open-sourced in early 2010.
The current version of HipHop, known as HHVM (or the HipHop Virtual Machine) was open-sourced in late 2011.
HipHop is currently around 2.7 million lines[Note 1] of mostly C++, C and PHP source code and is distributed as open source and free software on GitHub (under the terms of version 3.01 of the PHP License).
History Before HHVM
HipHop (known as HPHP) is an execution engine for PHP. Beginning in 2008, Facebook engineers began working on HPHP. The original release of HPHP was as a PHP to C++ compiler, known as HPHPc. PHP code was written and, when run through HPHPc, was transformed into C++, compiled into a binary and run as an executable (as opposed to being compiled to opcodes and interpreted). At the peak of HPHPc, PHP code showed dramatic performance improvements (up to 6x) compared to Zend PHP.
As an adjunct to HPHPc, Facebook engineers also created a "developer mode" of HipHop (known as HPHPi) and the HipHop debugger (known as HPHPd). This allowed developers to run PHP code through the same logic provided by HPHPc while, at the same time, allowing them to interactively debug PHP code. Developers could set watches, breakpoints, etc. Of course, the code run through HPHPi was not as performant as the code run through HPHPc, but the developer benefits were, at the time, worth having to maintain these two execution engines for production and development. HPHPc, HPHPi and HPHPd were all open-sourced in 2010.
By many accounts, HPHPc was a huge success, especially within Facebook as it allowed facebook.com to run much faster, using less resources. However, in early 2013, Facebook deprecated HPHPc. There were many reasons for this. For all the performance gains that HPHPc provided, the curve for further performance improvements had flattened. HPHPc did not fully support the PHP language, including the create_function() and eval() constructs. HPHPc required a very different push process, requiring an over 1GB binary to be compiled and distributed to many machines in short order. HPHPc did not support HPHPd, and, given the amount of lines of code that made up facebook.com, HPHPi was becoming slow for development. Plus, maintaining HPHPc and HPHPi in parallel (as they needed to be for production and development consistency) was becoming cumbersome. Finally, it was not a drop in replacement for Zend as external customers would have to change their whole development and build process to use HPHPc.
HipHop Virtual Machine (HHVM)
To solve the issues brought about by HPHPc, Facebook decided to create a PHP virtual machine. Foreshadowing the possible issues arising with HPHPc, development on the HipHop virtual machine (known as the HHVM) began in early 2010. HHVM builds on top of HPHPc, using the same runtime and extension function implementations. HHVM converts PHP code into a high-level bytecode (commonly known as an intermediate language). This bytecode is then translated into x64 machine code dynamically at runtime by a just-in-time (JIT) compiler. In these respects, HHVM has similarties to virtual machines for other languages including C#/CLR and Java/JVM.
HHVM brings with it many benefits over HPHPc. There is near full support for the entire 5.4 PHP language (including the create_function() and eval() functions). There is one execution engine for both production and development (i.e., no need to maintain HPHPi any longer). There is both production and development integration with HPHPd. And the push process becomes much simpler; no more lengthy binary build time that existed with HPHPc.
However, the key question is around performance. As a virtual machine, HHVM has the ability to use live type information to produce more efficient native code, leading to higher webserver throughput and lower latency. In Q4 2012, the performance of facebook.com running on HHVM achieved parity with HPHPc. In Q1 2013, the production version of facebook.com started running on HHVM, replacing HPHPc.
- After cloning the source from GitHub, running "git diff --stat 4b825dc642cb6eb9a060e54bf8d69288fbee4904" will provide the number of insertions from when a project was empty.
- "OOPSLA '12 Paper". Retrieved 2013-05-23.
- "QCon 2012 HipHop Compiler Presentation". Retrieved 2013-05-23.
- "FOSDEM 2013 Interview". Retrieved 2013-05-23.
- "HipHop for PHP: Benchmark". Retrieved 2013-05-23.
- "Drupal 7: HipHop for PHP vs APC – benchmark". Retrieved 2013-05-23.
- "HipHop For PHP - Move Fast". Retrieved 2013-05-23.
- "The HipHop Virtual Machine". Retrieved 2013-05-23.
- "Announcement on GitHub removing HPHPc support". Retrieved 2013-05-24.
- "GitHub issue discussion about PHP 5.4". Retrieved 2013-05-24.
- "Zend compatibility tests hosted on GitHub". Retrieved 2013-05-24.
- "State of HHVM in late 2012". Retrieved 2013-05-24.
- Official website
- HipHop Blog
- HPHP Facebook Group
- Internals of HHVM - talk given by HipHop engineer, Keith Adams, at QCon 2012
- HHVM Talk to Wikimedia in March 2013 - talk given by HipHop engineer, Andrew Paroski, at Wikimedia
- Scaling with HipHop - talk given by HipHop open source engineer, Sara Goleman, at PHP UK Conference 2013