There is little indication that Facebook isn't painful to deal with compared to a functionally identical version of Facebook built in another language/platform. Because someone did it and is profiting from it does not mean they could not have done it better.
It is called lex-pass [1], it does syntax aware transformations of PHP. Like sed, but specifically for PHP. There is a video that mentions it briefly at 2:00 min [2].
I thought most of Facebook's php is written in a subset of PHP that can HipHop can compile for them. I doubt their PHP is all that similar to eg. Wordpress's PHP.
Turns out * has some limiting factors [when serving 1 trillion page views a month]. Replace "*" with any piece of technology on the web stack.
There's not a single other company in the world (sans probably Google) that has to deal with performance problems on that level of scale. At that point, I can't imagine anything surviving out-of-the-box. Something has to give, even the language they're using (they're using a subset of PHP that they can run through a custom compiler to C++ machine code, to squeeze every possible CPU cycle out of the servers they have).