Site icon Geeknizer

Facebook’s PHP Runtime HipHop, now Open Source

In the need for speed, Facebook had been working under the hood to boost PHP runtime to crazy levels which were not possible before. Facebook has now Open sourced the underlying code, as predicted.

The PHP runtime has in fact been rewritten, but it comes with an extra effort: The PHP is translated to C++ (which is of course more efficient) which is then compiled with g++. The project is called HipHop and has been in development under great secrecy at Facebook for the past 2+ years.

With HipHop, Facebook claims to have reduced the CPU usage on average by about 50%. HipHop for PHP isn’t technically a compiler itself, rather a source code transformer. HipHop automatically transforms  PHP source code into highly optimized C++ and then uses g++ to compile it.

Apart from this, They have discussed the challenges faced while scaling a PHP application. Scripting languages like PHP, perl, etc are known to be far less efficient when it comes to CPU and memory usage than interpreted, compiled languages like C++, Java. All this creates it even harder to scale an application written in PHP.

Scaling Facebook is particularly challenging because almost every page view is a logged-in user with acustomized experience. When you view your home page we need to look up all of your friends, query their most relevant updates (from a custom service we’ve built called Multifeed), filter the results based on your privacy settings, then fill out the stories with comments, photos, likes, and all the rich data that people love about Facebook. All of this in just under a second. HipHop allows us to write the logic that does the final page assembly in PHP and iterate it quickly while relying on custom back-end services in C++, Erlang, Java, or Python to service the News Feed, search, Chat, and other core parts of the site.

Finding new ways to improve PHP performance isn’t a new concept. At run time the Zend Engine turns your PHP source into opcodes which are then run through the Zend Virtual Machine. Open source projects such as APC and eAccelerator cache this output and are used by the majority of PHP powered websites. There’s also Zend Server, a commercial product which makes PHP faster via opcode optimization and caching. Even compiling PHP isn’t a new idea, open source projects like Roadsend and phc compile PHP to C, Quercuscompiles PHP to Java, and Phalanger compiles PHP to .Net.

There’s in-depth discussion about how it works, at the source.

PHP is currently used by popular and large, dynamic web sites such as FacebookWordPress.com and Digg.  It was viewed as one of the hottest new technologies in 2005, when venture capitalist Marc Andreessen, founder of Netscape and current Facebook board member, told the Wall Street Journal that “PHP is to 2005 what Java was to 1995.”

What is notable now is – This new effort from Facebook could mold into acceleration for the industry adoption of PHP. The biggest bottleneck is now gone for good.

We write about Open Source, Programming, Web, Apple, iPhone, Android and latest in Tech @taranfx on Twitter.

Exit mobile version