No, I’m not talking about a break-dance move that will magically give you extra PHP performance. I’m referring, rather, to a new open source project announced by Facebook. HipHop is a “source code transformer” designed to reduce CPU and memory usage by transforming your PHP code into C++ code.
To understand why this helps, you need to know a little bit about how PHP works. PHP is a scripting language, like Ruby, Python, and Perl. This is great for developer productivity, as there’s no need for theĀ code to be compiled. The trade-off for this flexibility is in performance, with a scripting language requiring more CPU power and memory than a compiled language such as C++. What HipHop does is transform your PHP code into true C++ code, which can then be compiled into machine code. This is not the sort of thing you would do while developing, but when you are deploying your work you can compile it into the superior C++ code.
HipHop Performance Boosts:
- Web — 50% less CPU usage with the same traffic
- API — 30% less CPU usage with double the traffic
The performance boosts that Facebook has seen is based on its own real-world experience, with over 90% of Facebook servers being converted to HipHop code in the last six months. The benefits released were split into two categories, the Web tier and API tier, and the benefits witnessed for each. The web tier reduced 50% of server load with the same amount of connections, and the API tier saw a 30% decrease, even with a twofold increase in traffic. The difference is explained by the web layer requiring more presentation logic and more abstract information (related information) than the API tier.
What’s the catch?
You’ll have to avoid a few PHP functions, such as eval() and create_function(). Because of the dynamic nature of these functions, the HipHop team was unable to transform them into C++ code; however, these functions are rarely used in most PHP applications in general.
Currently your HipHop code has to run through a custom-written HTTP server bundled with HipHop; however, using HipHop code with Apache is high on the development road map.
While HipHop will increase the performance of your PHP code, it’s not necessarily going to be the silver bullet for your performance woes; for example, if your bottleneck is in your database performance, HipHop will be unable to help you. There’s no need to worry about it making your code slower though, as the entire PHP runtime has been emulated in a way that even the most complicated code will run at the same speed as pure PHP code.
Where can I find it?
HipHop will be released very soon to the open source community, but in the meantime you can read the full write-up on the Facebook blog, or view the Facebook presentation.
What do you think?
I’m interested in doing some benchmarks and seeing how HipHop performs with the SitePoint codebase. Do you think you’ll be checking it out when it’s released?
Related posts:
- Free PHP Webinar: How to Increase Performance with Caching Zend are running a free webinar today, with a live...
- Free Performance with MySQL Table Types Last week, SitePoint launched its second Twitaway, giving away a...
- Are PHP Namespaces Really So Bad? Namespaces have caused a divide amongst developers who either love...
- What’s New in Opera 10 (Part 2: Performance) In the second part of Craig's Opera 10 preview, he...
- How to Override PHP Configuration Options Moving your web application from a test environment to a...







here comes the hype..
February 4th, 2010 at 3:23 pm
Sounds like a maintenance nightmare to me – every time you make a change in your code, however small, you have to re-compile the whole thing?
February 4th, 2010 at 4:27 pm
Brilliant idea. I’ll be checking it out once it’s released. Thanks for the update!
February 4th, 2010 at 6:51 pm
I’ll definitely be checking it out when it is released!
February 4th, 2010 at 7:19 pm
Will you have to re-compile? Or does it work like .NET and re-compile automatically any time a change is made?
February 4th, 2010 at 7:48 pm
brothercake: I don’t see that as a major problem. Just write a routine to compile on save. I would guess that compilation is done quicker than you can move to your other monitor and click refresh ;)
February 4th, 2010 at 8:02 pm
@Dean C
I’m not convinced compiling would be that fast. HipHop pre-compiles PHP to C, then compiles that. Large applications would take time.
However, you could develop your application using the standard PHP interpreter then compile on release. The only issue: is a HipHop-compiled application guaranteed to work in exactly the same way? A single eval() could choke it, so you’d still need to test the resulting version.
Even so, this could be a viable alternative to Zend and other PHP optimisers.
February 4th, 2010 at 8:12 pm
I’ll want to know which (if any) web applications it supports. Particularly Drupal and WordPress.
February 4th, 2010 at 8:19 pm
@Joe
WordPress certainly uses a number of eval calls and there are quite a few dynamically generated function calls on runtime (especially for plugins). I doubt it’d work out of the box, but there’s no reason it couldn’t be fixed.
That said, WP speed isn’t much of a problem if you use plugins such as WP-SuperCache. HipHop may speed up the admin interface but, typically, that’s not frequently used by lots of users. The speed improvement could be negligible.
February 4th, 2010 at 8:27 pm
I will check it out when once it is released!
February 4th, 2010 at 10:38 pm
Before doing their stats, what was FB servers configuration (code caching boost a lot of perfs for example).
And, all this is screaming “big exploits incoming”.
February 4th, 2010 at 11:32 pm
Very cool. I must find time to check this out.
Thanks for sharing!
February 5th, 2010 at 6:43 am
You can compile for production and for testing you use the usual…
I think that for blogs and other basic websites it won’t be that useful. But for websites that have allot of traffic and/or use allot the CPU then it will be very useful.
I can’t wait to get my hand on it. I do have very intense CPU apps. This will really help and will make a big difference.
February 5th, 2010 at 7:10 am
@Arkh the performance boosts were on top of their existing apcaching so this is a boost on top of their already highly cached performance
@brothercake to be honest, for some people this may be a big increase in the workflow for deploying an app but, for example, every time we make a release here at Sitepoint we tag a release in GIT, then use scripts to deploy it across our cloud instances. Writing the code to handle the HipHop compiling would only take a few hours, and would only need to be done once – then the deploy operation from the developers end would be identical.
February 5th, 2010 at 8:41 am
@arkh re:exploits, if you watch the presentation from the developers (second link) you’ll see that they talk about how they had to ensure that the C++ version made EXACTLY the same amount of function calls, and had EXACTLY the same amount of traffic and connections through the servers. Because of this, there won’t be any new exploits as it’s running the exact same code.
February 5th, 2010 at 8:57 am
@jean-nicolas I forgot to mention in the article, but Facebook are working on an interpreter, HPHPi, that you can use during development.
February 5th, 2010 at 9:28 am
if you use WP or Drupal to build web site, 100% i can say, hiphop is not for you. the reason is WP or Drupal is for small web site.
after reading some articles on the internet, i see 99.99% person or organizations do not need the hiphop.
February 5th, 2010 at 10:44 am
i can’t wait until someone finds a serious bug in it…
i wonder how much testing has been done?
February 5th, 2010 at 11:22 am
@seanr They did testing for six months before deploying it. I think it’s pretty safe to say that after 6 months running the number one website on the internet that it’s a pretty rock solid product…
February 5th, 2010 at 1:03 pm
@brothercake
in development you don’t need to compile – only when releasing. So just make it part of your release script and that’s it.
However, I do see some other issues:
- who would be keen to switch to this custom-written http server? Configuring your webserver is a pretty important stuff if you care about security and performance. And if you don’t care about performance, why bother about HipHop?
- often the performance bottleneck is in a few scripts (eg a polling script). If you rewrite these scrips to a compiled language, possibly using multithreading, you can make huge performance improvements (ie 50% is not impressive in those cases).
February 5th, 2010 at 7:30 pm
Unless you become very aware of the consequences, this project is not for you .. Sooner or later PHP is implementing more advanced and sophisticated code and techniques that will be hard to convert into HipHop, you’ll need to contribute your self to writing the converter which I think is a big headache. HipHop is just for facebook and for today.
February 5th, 2010 at 9:36 pm
as with anything that is innovative, hiphop has yet to be thoroughly tested and flaws / problems identified. For the edge cases where websites are looking to squeeze every inch of performance out of their servers, then this could be a good investment as part of the deployment strategy.
February 6th, 2010 at 3:42 am
@almasry there’s no product lock in with HipHop, and if you wanted to move to a new version of PHP with new features that weren’t compatible with it there would be absolutely nothing stopping you, so your point is invalid.
I think that once the code is released and a few big sites get their hands on it and really test it we’ll know whether it’s a useful, viable tool or wether it’s a gimmick :)
February 6th, 2010 at 11:07 am
This is definetely good news! I am waiting for it!
You can boost your php apps by using cache methods like Pear’s CacheLite or out-of-the-box quickCache. Joomla, Wordpress, Exlis CMS, Drupal etc. have their own caching methods. But HipHop combined with cache methods mentioned above will definetely help!
Antonis @ http://www.01-global.net
February 12th, 2010 at 3:47 am