As predicted, Facebook has delivered a new PHP platform called HipHop for PHP that delivers much improved performance to the popular PHP scripting language that is known for its relative lack of performance.
As Facebook uses PHP extensively for many of its systems, the social networking leader put a small team of engineers together to come up with a solution to the PHP performance issues, as well as scalability issues-because scalability of dynamic, or scripting, languages has been an area of concern for some of the huge social networking platform providers. Twitter has had a number of difficulties in scaling Ruby. And Facebook set out to whip PHP into a scalable, well-performing, well-behaved citizen of its IT environment.
SD Times initially got wind of the PHP doings at Facebook.
Haiping Zhao, the Facebook engineer that launched the project, said, “Scripting languages are known to be far less efficient when it comes to CPU and memory usage. Because of this, it’s been challenging to scale Facebook to over 400 billion PHP-based pages views every month.” Yet, PHP is so popular because of its simplicity, he said. It is “Simple to learn, simple to write, simple to read, and simple to debug,” he said. “We are able to get new engineers ramped up at Facebook a lot faster with PHP than with other languages, which allows us to innovate faster.”
During the last two years the team toiled away in stealth mode, finally unleashing HipHop on Feb. 2. And despite the scale challenges, HipHop is showing a payoff. In a blog post about the new technology, Zhao wrote:
““Today I’m excited to share the project a small team of amazing people and I have been working on for the past two years: HipHop for PHP. With HipHop we’ve reduced the CPU usage on our Web servers on average by about fifty percent, depending on the page. Less CPU means fewer servers, which means less overhead. This project has had a tremendous impact on Facebook. We feel the Web at large can benefit from HipHop, so we are releasing it as open source this evening in hope that it brings a new focus toward scaling large complex websites with PHP. While HipHop has shown us incredible results, it’s certainly not complete and you should be comfortable with beta software before trying it out.”“
““HipHop for PHP isn’t technically a compiler itself. Rather it is a source code transformer. HipHop programmatically transforms your 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.”“
In essence, Zhao and the team set out to scale PHP to the point that it suited Facebook’s unique needs. Describing those needs and the benefits of the HipHop solution, Zhao said:
““Scaling Facebook is particularly challenging because almost every page view is a logged-in user with a customized 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 correct 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.”“
Zhao explained that a key idea for what eventually became HipHop originated at a Facebook Hackathon a few years ago, at which he worked on code to transform PHP into C++.
Zhao’s post spelled out more of the details of working on the HipHop project and building out the development team. He also said Facebook has developed a technology known as HPHPi, which is an experimental interpreter designed for development. “When using HPHPi you don’t need to compile your PHP source code before running it,” he said. “It’s helped us catch bugs in HipHop itself and provides engineers a way to use HipHop without changing how they write PHP.”
In summary, Zhao said:
““Overall HipHop allows us to keep the best aspects of PHP while taking advantage of the performance benefits of C++. In total, we have written over 300,000 lines of code and more than 5,000 unit tests. All of this will be released this evening on GitHub under the open source PHP license.”“
He also said Facebook engineers will be talking up the HipHop technology at various open-source and developer conferences, such as FOSDEM (Free and Open Source Developers’ European Meeting) and OSCON (O’Reilly Open Source Convention), over the next few months.