Why Facebook hasn't ditched PHP

Why Facebook hasn't ditched PHP

Summary: Have you ever wondered why Facebook is still heavily using PHP instead of just ditching the language at some point in the last eight years? A Facebook engineer recently answered the question.


Here's an interesting question I found on Quora: "Why hasn't Facebook migrated away from PHP?" Facebook engineer Yishan Sparklepants Wong worked at the company in various roles between December 2005 and March 2010. Keep in mind that Facebook launched in February 2004 so this particular engineer has been at the company for the majority of its existence.

Without further ado, here's Wong's answer to the PHP question:

The reason Facebook hasn't migrated away from PHP is because it has incumbent inertia (it's what's there) and Facebook's engineers have managed to work around many of its flaws through a combination of patches at all levels of the stack and excellent internal discipline via code convention and style - the worst attributes of the language are avoided and coding style is rigidly enforced through a fairly tight culture of code review (failing to adhere to the style and "going cowboy" by writing sloppy code results in pitiless mockery by one's peers). Engineering management has never had to take a strong hand here; this arose largely due to key internal technical leaders just sort of corralling everyone else along.

There is also a lot of industry precedent indicating that re-writing an entire codebase in another language is usually one of the worst things you can do, so at all levels there is a reluctance to do that. The preferred strategy is to write new components in a de-coupled manner using a better language of choice (C++, python, Erlang, Java, etc); this is easily facilitated by Facebook's early development of thrift, an efficient multi-language RPC framework. This also helps avoid the worst effects of PHP: it can be totally avoided in subcomponents where the language is grossly-unsuitable. The broad effect is that the overall codebase slowly evolves away from depending as heavily on PHP, with the components that are still in PHP being written in tightly-controlled, disciplined ways by veteran members of the staff.

Facebook doesn't just use PHP of course (Facebook may release its core C++ library this year), but it is heavily invested in the language. If you could go back and convince Zuckerberg to use something other than PHP, what would it be?

See also:

Topics: Social Enterprise, Software Development

Emil Protalinski

About Emil Protalinski

Emil is a freelance journalist writing for CNET and ZDNet. Over the years,
he has covered the tech industry for multiple publications, including Ars
Technica, Neowin, and TechSpot.

Kick off your day with ZDNet's daily email newsletter. It's the freshest tech news and opinion, served hot. Get it.


Log in or register to join the discussion
  • If'n I culd go back...

    Atari BASIC
    • ..............

      1 million X Like, haha I started on Atari BASIC!
      But really I dont think any other language would have been better for fb than PHP, PHP gets the job done and has many ppl that can code it
  • Not sure how useful this speculation is

    In 2004, Java was a slow mess with a patches coming more often than those for Adobe Flash (still is, but that's beside the point).

    So you realistically had a choice between ASP or PHP. Pre-.NET ASP was a mess, so realistically PHP was the right tool for the job.

    I have to laugh at the notion of "migrating" like it's something to do on a Saturday afternoon when you have nothing else to do. That's like your neighbor asking you why you haven't changed your car's color yet? Yeah... I'll get some masking tape and get right on that!
    • .NET is a mess too, and will never be able to scale up

      Atleast Java can scale better than .NET. One of the common refrain you keep hearing nowadays is that IT departments should have invested in other technologies and environments too. .NET and Java standardization has led to aging architecture as well as infrastructure that seems almost next to useless in the BYOD world. Most corporate T support teams are not able to cope with non Java and non .NET systems.
      • What are you based on?

        Today, .NET is no doubt the most advanced enterprise platform in terms of modernity, language construct, productivity, and tooling. I've been working with Java, .NET and PHP and can say that while Java was the good choice for enterprise applications, today it looses constantly market share due to the non-evolution/immobility and implementation costs. PHP has greatly evolved from the simple ad-hoc web site scripts to full web platforms, but it's still web-only oriented and not enough structured and powerfull as engine for the enterprise.

        During the last years, .NET got one by one the missing components - ASP.NET web forms vs MVC vs Sharepoint enterprise portal, presentation on desktop via WPF/WinRT on Win 8, powerfull (and scalable) services via WCF, integration, workflow, powerfull database, event processing, master data management, and much more. And I can say that when you put this on paper, the overall costs for the .NET implementation are lower, at the end, than any other choice.

        And as a suggestion for replacement, if desired: ASP.NET MVC on Azure Web Roles.
        • do you work for microsoft... or for crack??

          there is not one large scale site using ASP.NET for a reason... it is not scalable. Not to mention, where security is concerned, Microsoft has a worse track record then Fat Albert!

          PHP, written well, is the fastest and most scalable and secure language for server side programming, period. Can it be written poorly, of course. But, so can C/Java/etc...
      • Support your statements

        How does Java scale better than .NET? Every study I've seen shows that they are about even as far as performance. What do you mean by aging architecture? What does the language you code in have to do with infrastructure? Why is Java/.NET useless in a BYOD world?
  • As if it was a bad choice?

    Python or Ruby would have been better? PHP was and still is a fine choice.
    • PHP is slow in larger applications

      PHP is great for forms and small applications, but you run into speed issues with larger applications. PHP also allows your team coders to be flexible and sloppy, much like Perl. So yes, Python/Django would have been the better choice.
    • PHP

      I'm no expert at PHP. However, my last encounter with it gave me the impression that it is very unstructured...kinda like classic asp with more of an object oriented approach. This can lead to bad coding habits if you don't have strong coding standards, which it sounds like Facebook does. Agreed, if it works for them and they can stay on top of code reviews, why change it?
  • sometimes people should just mind their own business

    leave well enough alone.
    don't rock the boat.
    if it aint broke, don't fix it.
    • I totally agree

      I totally agree, if it is not broken, than don't fix it.
    • software optimization

      What about software optimization?!
  • Are there any good reasons

    Are there any good reasons to move away from PHP? Seems to be going great from where I'm sitting. Sounds like the team is savvy enough to have managed the shortcomings well (as they would have to with any language / framework).
    'Leave it be' sounds good.
  • 37signals just redesigned Basecamp...

    ...and they're sticking with Ruby On Rails (which they helped launch) and advanced caching and JS. They were happy staying on MySQL. Great article.

    PHP likely isn't a huge bottleneck; it's more and more on the client side (though it might be a different game on the mobile app side, where the UI is 'there' and it's all small data requests).

  • Nothing wrong with PHP

    It's just another server language.

    However, if they really wanted to stuff it up and make it around 200% slower then they could try Java ;-)
    • That's (A bit) wrong

      Wow, you could not be more wrong. Just ask yourself why do all server-side applications where performance matters use C or Java. I'm talking about sub-microsecond trading exchanges... Java's VM is so pioneering that FB are implementing a VM for PHP (called HipHop), look it up.
      • Java is not faster then php.

        Java simply is not fast then php except in a couple of areas. This is a fact. Although you hear the opposite from Java programmers all the time. They have an in house php compiler that creates C++ code from php, making it WAY faster.

        They are using hiphop for a small segment of code.
  • Wow

    Does not surprise me that they have to chnage something.

    Why change? PHP is as stable and reliable. Make sense and besides, is there a problem with something that works?