Get $500+ of the best After Effects files, video templates and music for only $20!
Facebook Hopes to Revolutionize PHP with

Facebook Hopes to Revolutionize PHP with “Hip Hop”

Little did we know that, for the last six months, Facebook has made use of a custom compiler for PHP that they refer to as “Hip Hop.” Essentially, it takes your PHP source code, and converts it into C++, and is then compiled with G++. As a result, they’ve managed to reduce their CPU usage by 50%. This project has apparently been in development for the last two years, but has only today been released to the community.

“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.”

The Announcement

“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 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.”

The Problems Facebook Faced with PHP

  • Can’t reuse PHP logic in other systems
  • Extensions are harder to write for PHP developers
  • High CPU usage; can’t be as efficient as something like C++
  • Fully impractical to completely rewrite Facebook with a new language

How They Improved It

  • It’s a source code transformer
  • Transforms PHP into optimized C++, then compiled with G++
  • Has been in development for over two years.
  • If you’ve used Facebook within the last six months, you’ve experience Hip Hop
  • Facebook team have recorded a 50% decrease in CPU usage.
  • They’ll have dedicated evangelists to help train/familiarize the community with Hip Hop
  • If you’re on a shared host, using Apache, you’ll most likely want to continue using standard PHP
  • Where Can We Start Playing with It?

    Hip Hop is available now, and is hosted on Github. You can download it here.

    Hip Hop Process Graph

Add Comment

Discussion 68 Comments

Comment Page 1 of 21 2
  1. Andreas says:

    interesting stuff… they have the money… they deliver good things for the community…

  2. Imran Khan says:

    php to C++ kind a interesting….

  3. WP Tricks says:

    I am didn’t understand about php and g++ but it’s look like interesting method

  4. edfuh says:

    My entire belief system has been shaken.

  5. Can Berkol says:

    hardcore. i bet they still need more optimization. it’s amazing how they survive that many human driven database transactions with so few losses.

  6. Zulfur Raju says:

    The download link is not working

  7. Nicko Picazo says:

    2 thumbs up for facebook developers! very interesting!

  8. Armin says:

    So, where can we get it to test it out?

    the github page doesn’t exist (heres facebook’s repo: http://github.com/facebook/)

  9. Way says:

    Great stuff and a good push for php. Keep going fb!

  10. uu12nal says:

    Hi,

    Video don’t play video

  11. Skunkie says:

    Writing a code transformer for the used language in order to avoid having to rewrite the whole site in another language – what a strange and funny idea this is. But if it works – cool!

  12. DesignLovr says:

    I’m not sure if the average php-guy will actually profit from such a complex code transformer, but I definitely appreciate the effort!

  13. Is this why Facebook is so rubbish now? For the last 6 months I have seen ‘An Error has Occurred’ or ‘Something Has Gone Wrong’ being reported by numerous friends. It is why I switched to Facebook Lite.

    Great idea but shoddy, bug-ridden code….

  14. c0mrade says:

    Has anyone managed to open this link?

    http://developers.facebook.com/hiphop-php/

    Is the code released yet?

  15. I don’t know if the link on the other page isn’t working, but http://github.com/facebook/hiphop-php takes me to the main github.com page.

  16. khaled says:

    Nice stuff! wow

  17. Great news for the PHP community!

  18. Chandrashekar says:

    Intresting I love PHP and have explored as much as i could but this is something i always thought about “cpu usage associated with php”, great that it is implented like this and in on of my favorite site, kudos facebook team.

  19. Chandrashekar says:

    Intresting I love PHP and have explored as much as i could but this is something i always thought about “cpu usage associated with php”, great that it is implented like this and in one of my favorite site, kudos facebook team.

  20. It’s about time PHP became JITed. It’ll be interesting to hear what the zealots, for the lack of a better word, say.

  21. Patrick says:

    This is absolutely useless for small php devs. This tool is ONLY for websites with really high loads and traffic. This is NOT for small sites like tutsplus-Network or something like them.

    And the name… Terrible. Hip Hop for PHP. Pure nonsense.

    • Torkild Dyvik Olsen says:

      That’s not true at all. Yes, you will have much more to save with a large site, but you will still have something to save on smaller. I’m not saying you should start using HipHop on your blog right away, but you should maybe think about it if your blog gets enough hits.

      I know little about Tuts+ hosting, but I guess they have control over their servers, and might have both money and environment to save by implementing something like HipHop.

      Regarding the name, I kind of agree with you. It’s not terrible, but definitely not good.

  22. Paul says:

    praise php all u want…RUBY WINS!!!

  23. Dimitar Stoyanov says:

    It looks like HipHop is not available for download… http://github.com/facebook/hiphop-php is not exists, it returns to Github’s index page.

  24. no says:

    You could always improve your sites by not using php in the first place.

    What a duh moment.

    • Patrick says:

      u’re kidding us, right? It’s really possible to code high performance sites with php. It just need advanced skills and wise ideas.

    • Bretticus says:

      Apparently, you forgot about twitter being down about every day for months on end. So much for Ruby on Rails scalability. ;)

  25. Sean Foushee says:

    Seems like an ingenious way to get around rebuilding the service in a different language, but I wonder how reliable the “transformer” is and what sort of coding practices it requires from developers to ensure eveything is transformed and compiled properly.

    Definitely on my “to-do” list for this month. Thanks for the post!

    • lilwiki says:

      “Reliable” !!! Facebook is using it in 90% of page fetches.

      As regards to coding practice, I don’t know what to think at the moment. They built it (hiphop for PHP), then applied it to an existing code base, thats a more positive signal than if it were the reverse.

  26. sergi says:

    i love the fact that they were brilliant enough to invent the compiler, then successfully implement it, then release it to “us”. kudos to facebook.

  27. Burak says:

    This could be an alternative to Zend Guard.

  28. Khalil says:

    great technology… how can we use it with php?

    Thanks for sharing.

  29. Systrix says:

    HipHop seems really interesting, we have had to switch to lighttpd and xcache to achieve huge performance benefits for our objectCMS framework which is now faster that wordpress, joomla and drupal. I am wondering how hiphop compares to lighttpd and xCache, does anyone know when hiphop is going to be released to the public.

  30. koder says:

    the link doesn’t work!!!!

  31. Shane says:

    It’s a little short-sighted, but also inevitable, that some people have chosen to pick on PHP’s suitability for large sites, when the site in question is one of the biggest on the whole of the internet.

    From a technical standpoint, it’s very interesting, but the fact is that PHP would never be as fast as optimised C++, so what they’ve done is both ingenious and thought-provoking.

  32. Ed says:

    This is very cool!

    I do a lot of PHP work but I also do a lot of ColdFusion work as well and most people don’t know that ColdFusion like PHP is a scripting language – but the key difference is ColdFusion compiles into Java that runs in any J2EE server and the kicker is, they have been doing this for years now…

    I like both development tools, but I have to give credit to ColdFusion for being ahead of the game on this aspect.

  33. Matt says:

    I saw Jeffery tweet this last night, and I was like “8 hours until Nettus post, clock it”

    I was right.

    Also, this sounds awesome, though I guess it still doesn’t do much for PHP on the desktop front (though, it was never supposed to).

  34. itpixels says:

    this is pretty exciting…but i’m just wondering if it can be beneficial for small to mid scale systems…

  35. Stephen Coley says:

    I’m curious as to whether they’ll begin writing new Facebook code in C++ now that they have Hip Hop to convert their original code, or if they’ll run new PHP code through Hip Hop.

    There CPU usage may be down, but I’ve noticed Facebook being very buggy these past six months.

  36. Talal Bin Ghizal says:

    where is hiphop ?

    Github returning to index page when visiting this url:

    http://github.com/facebook/hiphop-php

  37. Robert says:

    This is a great approach by facebook. Even tho in the agency where I work we’ve got in house C++ gurus and when we are making something really heavy we take another approach; writing a driver for Apache which I think is more suitable than this approach. I’m not a heavy user of Facebook, but the little experience I have with C/C++ tells me that facebook will run into lots, and lots of bugs unless they’ve managed to do something really revolutionary.

  38. I decided to create an application that uses the Facebook Platform. writing the application in PHP and I thought it might be useful for others to know how to write their own Facebook PHP applications.

  39. ellisgl says:

    I wouldn’t call it revolutionary, since it’s not going to convert all PHP into C++, since there are a lot of restrictions. But I believe that this will help a lot with GTK in the future.

  40. nathan says:

    Why not to improve php itself, rather than transforming it into c++?
    Though I appreciate Facebook guys’ work.

  41. Robin Varghese says:

    Wow Amazing approach by facebook

  42. sam says:

    .NET any one?? lol

  43. webcodez says:

    Sounds interesting, go Facebook – nice post.

  44. Harsha M V says:

    nice… lets explore it

  45. Arun says:

    Nice work !!!

  46. doopromotion says:

    Hip Hop can run on Apache2.2? I want to use it for improve my app. Thanks for share about information.

  47. Cool technology… Thanks for sharing.

  48. Haha. Now ASP.Net has some competition. ASP.Net always used the excuse that their source code is compiled so it runs faster. Now PHP has come back fighting thanks to Facebook.

Comment Page 1 of 21 2

Add a Comment

To add a code snippet to your comment, please wrap your code like so: <pre name="code" class="html">YOUR CODE</pre>. You can replace the class name with "js," "css," "sql," or "php." If there are any "<" or ">" within your code, please search and replace them with: &lt; and &gt; respectively.