Facebook Writes PHP Compiler (Update)

by pieterh on 03 Feb 2010 09:05

Facebook's Haiping Zhao explains how he's been working for two years on way of making PHP run much faster. Facebook is now running that on 90% of their servers and they will release the source code this evening. This could be very interesting for Wikidot, since we use PHP and any improvement in performance would be great.

On his blog, Haiping Zhao explains that:

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.

Converting PHP into C++ and then running the GNU g++ compiler is in effect creating a PHP compiler. For many years C++ was itself compiled like this, first converted into C and then that intermediate code compiled.

The limitations of this system are that PHP extensions will need to be rewritten, so most likely HipHop is today only going to work for simpler PHP applications (and Facebook itself). But releasing it as open source is a smart move. It means other teams — like us — will try it, extend it and improve it.

Comments: 0

Add a New Comment