On 2nd February, 2010 Facebook announced a new project by a small team of Facebook developers who were working on for the past two years; HipHop for PHP. Facebook claims with HipHop they’ve reduced the CPU usage on their Web servers on average by about fifty percent, depending on the page and as well know less CPU means fewer number of servers, which means less overhead for high scale applications. They also claim that this project has had a tremendous impact on Facebook as it helped in reducing the huge overhead of over 400 billion PHP-based page views every month. The Web at large should benefit from HipHop but its in beta phase now so developers will have to accommodate with it before trying it out.
According to Facebook HipHop for PHP isn’t technically a compiler itself. Rather it is a source code transformer. HipHop programmatically transforms PHP source code into highly optimized C++ and then uses g++ to compile it. HipHop executes the source code in a semantically equivalent manner and sacrifices some rarely used features — such as eval() — in exchange for improved performance. HipHop includes a code transformer, a reimplementation of PHP’s runtime system, and a rewrite of many common PHP Extensions to take advantage of these performance optimizations.
PHP belongs to the category of scripting languages and they are known to generally be less efficient when it comes to CPU and memory usage and according to Facebook:
One common way to address these inefficiencies is to rewrite the more complex parts of your PHP application directly in C++ as PHP Extensions. This largely transforms PHP into a glue language between your front end HTML and application logic in C++. From a technical perspective this works well, but drastically reduces the number of engineers who are able to work on your entire application. Learning C++ is only the first step to writing PHP Extensions, the second is understanding the Zend APIs.
Since 2007 we’ve thought about a few different ways to solve these problems and have even tried implementing a few of them. The common suggestion is to just rewrite Facebook in another language, but given the complexity and speed of development of the site this would take some time to accomplish. We’ve rewritten aspects of the Zend Engine — PHP’s internals — and contributed those patches back into the PHP project, but ultimately haven’t seen the sort of performance increases that are needed. HipHop’s benefits are nearly transparent to our development speed.
The project has taken two years: eight months to have a version that could be demonstrated, ten months finishing up all the coding, and six months testing the service on production servers and developers have written 300,000 lines of code and more than 5,000 unit tests.
The whole thing sounds very interesting and I guess it will create a buzz in millions of open sources developers but unfortunately the source code link provided by the HipHop Wiki seems broken but I’ll still follow the instructions and give it a try.
You can also check out Facebook’s video on HipHop for PHP:
Courtesy: HipHop for PHP: Move Fast