Facebook's HPHP: Initial Comments

Facebook have announced a significant project around PHP that I saw previewed at a small tech summit last month. No, Facebook did not announce PHPVille.

Facebook announced HPHP, pronounced hip-hop. "HipHop programmatically transforms your PHP source code into highly optimized C++".

Have you hovered over the word 'Facebook' in the copyright banner of any facebook.com page? Chances are that it says "HPHP", indicating that the server handling your request was running it. Ninety percent of their web traffic is delivered by it and rollout across their servers continues.

What do we know about HPHP? Cherry picking just a few facts from my notes:

  • Takes a complete PHP application and generates equivalent C++ code
  • For Facebook's (huge) application, they end up with a 1Gb binary
  • But this includes a built-in multi-threaded webserver
  • No SSL yet
  • Has XHProf gatherer built in. Facebook run this in production with a configurable sampling rate
  • All extensions are currently statically linked
  • Runs one process multi-threaded
  • Has its own configuration file syntax: no .htaccess equivalent, but does support virtual hosts
  • The performance benefit of HPHP being quoted is "on average it's about a 50% CPU saving". This is with g++ and the Gold linker. Database-heavy pages aren't going to benefit as much as PHP-centric pages

Although in the best Silicon Valley spirit HPHP is being called Beta, I'd say it is at the end of Alpha (or it was when I saw it). However it would only take tidy-ups to the build infrastructure to stabilize the experience.

Writing extensions involves starting with an IDL file describing the extension API that PHP scripts would call. A template C++ file with stubs is automatically generated from the IDL file. After that it's all your own C++ code. When HPHP becomes generally available I'll be interested in digging into this more.

A number of core extensions have been ported. Some way to use other existing PHP extensions was high on the summit attendees' wish-lists. There are some technical issues with globals and I don't know if Facebook will spend time on this, since they don't have a business requirement for it.

Quality and compatibility of HPHP appears high. I understood that a lot of development at Facebook still uses PHP even though the code is then deployed with HPHP. Facebook HPHP testing included comparisons with PHP:

  • comparing the number of functions being called
  • comparing network I/O
  • comparing Error Logs

Details about which PHP version HPHP is compatible with (PHP 5.2.5) and what extensions are supported could soon be irrelevant as Facebook continue working on HPHP and if a community forms around it. My notes on Facebook's stated roadmap say:

  • Make it work with Apache
  • Catch up with PHP 5.3
  • Minimize differences between HPHP and PHP

These indicate recognition that the crux of building a community is getting adoption. There have been other re-implementations of PHP in the past. Where have they got to? This new implementation has some clout behind it and there is vigor to create a community. Also I don't doubt Facebook will continue to use and improve HPHP and this might make it enticing to sites that have issues with capacity. The rest is up to you.

Finally, what else was discussed at the summit? Discussions ranged from specific implementation details about facebook.com to how Facebook could work with the PHP community. There was a significant exchange of information in both directions.

I'll briefly mention Memcached, which was of particular interest on the day. Facebook faced a lot of questions about its use and the improvements they've made (64-bit, UDP, multi-threading, ethernet drivers, compression, locking, batching, hashing). Facebook's UDP support has been mentioned at PHP conferences and is something people latch onto as if they had been dreaming of it all their life. However it brings complexity and has its own problems that had to be solved, including issues with handling large objects. Facebook also found UDP worked well when their datacenters' latencies were all the same, which is not always true now for them. Facebook stated they hope to merge back their useful Memcached changes to the open source community.


Thanks for the insights, Chris. One question. You mention "The performance benefit of HPHP being quoted is "on average it's about a 50% CPU saving"." Do you know if that's 50% saving against plain vanilla PHP or 50% against already "compiled" PHP using APC or Zend Core code accelerator or the like? Because if it's just against plain PHP, I'd like to see some comparison against the APC accelerated code. Michal

Posted by Michal Taborsky on February 02, 2010 at 06:17 AM PST #

Michal, I understood the numbers to be comparisons with their previous operational deployments, which would have meant vs. APC. Chris

Posted by Chris Jones on February 02, 2010 at 06:34 AM PST #

APC doesn't provide any execution speed benefits as it simply stores a copy of the processed opcodes in memory and uses that on further script execution. The figures that were given out were based on an internal optimized version of stock PHP, including APC. It wouldn't be possible for us to provide stock PHP figures as we simply can't run that here.

Posted by Scott MacVicar on February 02, 2010 at 07:36 AM PST #

Some other blogs to read: http://blog.tabini.ca/2010/02/hiphop-what-you-need-to-know/ http://ilia.ws/archives/213-My-Thoughts-on-HipHop.html http://terrychay.com/article/hiphop-for-faster-php.shtml http://php100.wordpress.com/2010/02/03/hiphop/

Posted by Chris Jones on February 02, 2010 at 08:19 AM PST #

This is very interesting - where can I find more info about this? Does Facebook publish any info, or have a developers site?

Posted by Emma on February 15, 2010 at 09:31 PM PST #

Post a Comment:
Comments are closed for this entry.

Tourists looking out over an Opal mine
I'm a Product Manager in Server Technologies, working on scripting languages and developer-access.
Mail: christopher.jones@oracle.com
Twitter: @ghrd
OTN: Scripting Languages
Book: Free PHP Oracle book

Blaine Carter
Dan McGhan


« July 2016