HipHop for PHP

Accepted Session
Short Form
Scheduled: Thursday, June 3, 2010 from 2:30 – 3:15pm in Burnside


HipHop transforms PHP source code into highly optimised C++ and then compiles it using g++. It allows developers to continue writing complex logical directly with PHP but leverages the speed benefits of using C++. Currently, HipHop powers the majority of Facebook servers, making this more than just a theoretical exercise.

This session will cover how HipHop works, how to setup HipHop and the small changes that may be required to applications to allow it to work with both PHP and HipHop.


The main challenge of the project was bridging the gap between PHP and C++. PHP is a scripting language with dynamic, weak typing. C++ is a compiled language with static typing. While PHP allows you to write magical dynamic features, most PHP is relatively straightforward. It’s more likely that you see if (…) {…} else {..} than it is to see function foo($x) { include $x; }. This is where we gain in performance. Whenever possible our generated code uses static binding for functions and variables. We also use type inference to pick the most specific type possible for our variables and thus save memory.

The transformation process includes three main steps:

1. Static analysis where we collect information on who declares what and dependencies,
2. Type inference where we choose the most specific type between C++ scalars, String, Array, classes, Object, and Variant, and
3. Code generation, which for the most part is a direct correspondence from PHP statements and expressions to C++ statements and expressions.

We have also developed 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. It’s helped us catch bugs in HipHop itself and provides engineers a way to use HipHop without changing how they write PHP.

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.

Speaking experience


  • Haiping


    Haiping Zhao is the Senior Server Engineer at Facebook and is leading the HipHop compiler team and is responsible for the web server software compiled with the compiler. Haiping joined Facebook as Server Architect at Plaxo, who is one of the earliest social networking companies and who was later acquired by Comcast. Prior to Plaxo, Haiping also worked on .Net Transaction Team, COM/DCOM Team, and SQL Server internals (MSDTC) from Microsoft. He also served as Server Architect/Engineer for startup companies DispenseSource and OmniCell, speciailized in inventory management. He graduated from Princeton with a master degree of Computer Science, and also a master degree of Pharmacology and Molecular Biology from New York University Medical Center.