HipHop Your Way To PHP

A few days ago facebook released (under opensource) their HipHop for PHP source code transformer. I remember first reading about this from an interview with a facebook employee on reddit. She mentioned that one guy was pretty much rewriting PHP to work on C++, which at the time sounded like they were working on some compiler. The actual product though is different, they basically convert the PHP source into C++ code, and then you can use your compiler of choice (probably g++) to get it up and running. I know something about this area as my final year project at uni I created a code transformer that would take a web script in PHP -> JSP -> ASP and convert it into any of the others. You could basically go in any direction – plus you could add in new modules for other languages that would allow you to transfer between even more. This was far from completion (I had it working for about 50% of common functionality) but I proved that it could be done – I also showed that you could optimize the code quite significantly. I basically added rules that would find common coding patterns and transform these in the AST (abstract syntax tree). Transforming to the new language was relatively easy as the tree was already in a good shape and the transformer knew how to properly express the tree in the most optimized way. The way I see it – HipHop has the opportunity to not only transform but optimize the hell out of the code as well. They say that in practice they are seeing a 50% CPU decrease and much better memory overhead.

I believe that the current version is compatible with PHP5.1 and they are quickly looking to get it compatible with 5.2. There are also some bits that it wont do, such as the rarely used eval() statement and function exists checking – these are things that they cant link to as they don’t know they exist, therefore can’t compile against

I have always liked PHP and have watched it get better and better to the point of it being a very professional tool in the right hands. I still regularly use PHP for my own applications that I need to get out the door quickly and effciently. What makes this interesting to me is that I can also look at it as a tool of choice for applications where I wouldn’t have before used PHP. I will have to play with it a bit and see what it can do. I think it will get more interesting when they get a version that can run on Apache/lighttd etc.

Go and get the code for yourself and check out the video for further information.

For more information on the technical challenges they face scaling Facebook, take a look at this article which goes into a deep enough description.

2 Comments so far

  1. John on February 6th, 2010

    I can see this being used for my game.. If it works with cakephp :D

  2. Landon Wainwright on February 11th, 2010

    Yeah John, I was thinking of that actually. Will be more use to you if the game took off and it had to scale. I don’t think it would be much use to you before that. I don’t know if it will work with cakePHP because the frameworks usually use some of the “magic” functions to get the magic functionality, which would stop it from working. But I have no idea whether this is the case or not for cakePHP. I suppose you would have to try and see :)

Leave a Reply

Or you can login using your facebook account