
Facebook Porting PHP To JVM - code-dog
http://nerds-central.blogspot.com/2012/08/facebook-moving-to-jvm.html
======
kingkilr
At this point I have to just laugh. They literally already paid for the
development of a prototype for a faster PHP, and decided not to pursue that
route: <http://morepypy.blogspot.com/2012/07/hello-everyone.html>. I have to
assume they have some insane internal politics, because there's no sane
technical reason to develop HipHop (static subset-of-php to C++ compiler),
then start the HipHop VM, then fund the PHP on PyPy prototype, and now
apparently move to a PHP on the JVM.

~~~
theshadow
I don't understand what's wrong with exploring your options. Why would you
assume that the reasoning has something to do with politics rather than trying
to find a better technical solution to their problem?

~~~
kingkilr
They're not exploring a research space, they're exploring a space where the
options are incredibly well known, and they're jumping from solution to
solution, even after they appear to find a success.

~~~
sanxiyn
If they have enough resources, they can afford to try all options in parallel.
Wasteful, but although it may seem strange, it isn't like programming language
implementation engineering is expensive compared to data centers.

------
abolibibelot
Phalanger ( <http://phalanger.codeplex.com/> ) is an implementation of PHP
running on the CLR with a fairly good compatibility story and sometimes much
better performance.

Phalanger worked well even without using the DLR (dynamic language runtime) so
a JVM implementation shouldn't be a massive undertaking (except for the lexer
and parser parts...)

------
nickmain
There are already at least 2 implementations of PHP on the JVM:

<http://quercus.caucho.com/> <http://www.projectzero.org/php/>

~~~
boyter
Has anyone around here actually used either of the above and care to comment?
I would be curious to know how compatible they actually are with the average
chunk of PHP code, and if not how hard it is to work out whats wrong and get
it running.

~~~
sanxiyn
Quercus is known to run WordPress, MediaWiki, and Drupal without patches.

------
scottmac
I work at Facebook and have been involved in the Hiphop for PHP project for
the past few years.

We have our own VM written and it isn't based on the JVM.

Bytecode: [https://github.com/facebook/hiphop-
php/blob/master/doc/bytec...](https://github.com/facebook/hiphop-
php/blob/master/doc/bytecode.specification)

Code: [https://github.com/facebook/hiphop-
php/tree/master/src/runti...](https://github.com/facebook/hiphop-
php/tree/master/src/runtime/vm)

------
jacques_chester
It should be noted that there is _no direct evidence that this is happening_ ,
other than:

"The presence of Facebook engineers at the Java Language Summit in San-
Francisco"

Is the author aware that Facebook is a multi-language shop? It's why they have
Thrift, after all.

~~~
sanxiyn
Why do you quote selectively? The next part is: "along with their interest in
implementing PHP using invokedynamic on the JVM".

Also, JVM Language Summit, not Java Language Summit. (OP got it wrong too.)
More on <http://wiki.jvmlangsummit.com/Main_Page>

~~~
jacques_chester
I quoted selectively because the author gave no source for "their interest in
implementing PHP".

None. No links. No names. No quotes. No press releases. No blogs. No email
archive. Nothing. Not a skerrick. Not a sausage. Not a sniff.

~~~
sanxiyn
Most likely this was a hallway conversation at JVM Language Summit (which it
seems that OP attended). I don't see any particular reason to doubt his claim.

~~~
jacques_chester
I do, because he seems to have a bee in his bonnet about the evils of
interpreters.

I'm also a bit wary of leaping from one-guy-musing-in-a-hallway to FACEBOOK
PORTING PHP TO JAVA.

------
stephen_mcd
It's the summer of 2018. Facebook shares drop to 17 cents as their PHP to ASM
compiler project nears completion.

~~~
code-dog
No reason it should take that long. The article suggest 6 person years - which
could mean 6 people for 1 year.

~~~
kyriakos
try reading The Mythical Man Month
<http://en.wikipedia.org/wiki/The_Mythical_Man-Month>

unfortunately my boss thinks as you do..

~~~
josegonzalez
You either never read the book or are interpreting it wrong.

The premise is that as you add more people to an EXISTING project, the amount
of time it will take to complete will increase. However, if all of those
people are involved from the beginning, then you are not subject to the same
phenomenon - within reason of course.

So while it might not be "6" developers working on it for a year, it could
potentially be 9 very devoted developers cranking this out with good results
towards the end of the year.

~~~
Danieru
Brookes also talks about another issue, that in a team of 6 there are (6
choose 2) edges in the communication graph. I think this is what kyriakos was
referring to.

------
lukev
I guess someone must _really_ love PHP, though I'm slightly confused as to
why.

If you're going to make such a massive undertaking anyway (it's not just the
new runtime, all existing code will have to be re-tested and re-debugged), why
not sink the man-hours into putting it into a new language better suited to
the task from the start?

~~~
fleitz
Because there are millions of man hours of PHP from FB and it will cost less
than one hundred thousand to port that work to the JVM.

Yes the code will have to retested, but if you rewrite then you rewrite AND
retest. Working code makes a great test suite, something you lose in a
rewrite.

~~~
lukev
Yes, that sounds fine (and I'm aware of the Spolsky article posted in another
comment.)

But the fact is that a system of that size simply _must_ already be split up
into discrete services or components. (If it's not, then that should be their
first priority. But I can't imagine Facebook is running everything they do out
of one process).

So they could port each service/component one at a time, rigorously testing
and improving performance as they go. Then they'd not only get the benefit of
a better runtime, but also a safer, faster language. In fact, if they're
anything like most companies I know, they're _always_ in the process of
rewriting one service or another to improve performance or features, whether
in a new language or not. All they'd need to do would be to switch to the new
language whenever they were refactoring existing code anyway.

Of course I can't make the decision for them, and they are rightly hesitant to
do an entire rewrite. But it seems like they're going to fairly extreme
lengths to stay with PHP.

~~~
swah
> But the fact is that a system of that size simply must already be split up
> into discrete services or components.

Come on, they created Thrift, I think we can assume they use it?

------
prezjordan
Why do these companies like the JVM so much? Twitter, and now Facebook. Does
it have that great of performance?

~~~
jrockway
Yes. [http://shootout.alioth.debian.org/u64q/which-programming-
lan...](http://shootout.alioth.debian.org/u64q/which-programming-languages-
are-fastest.php)

Note that Java compares very favorably with C. (Of course, the real thing to
take away from that chart is: why don't all the JVM users switch to Haskell?
It's more concise, safer, and has a better community.)

~~~
SkyMarshal
Many JVM developers for whom programming is craft rather than a day job are
definitely looking at both Scala and Haskell. Lots of excellent stuff going on
with both, as you point out - concise, safer.

~~~
mitjak
I'll just have to trust you on that I suppose.

~~~
code-dog
That is true. As someone who thinks both ways (craft and day job) the issue
with Scala (that with which I have the most experience) is the tooling.

------
hdoan741
Is there any official reference to backup the claim? I doubt Facebook would
spend effort on doing this since they have already port PHP to C++ with
Hiphop.

------
krob
Lets ask this one question. Why rewrite python in python? Why rewrite Ruby
with java? They may have realized that php is a good solution for their
existing framework, the framework has an enormous unit test harness, which
would take a very long time to translate, and they have nothing against the
language at the company. If they are planning a jvm for php, it is probably
because they have developers there who have experienced the speed increase of
other jvm langauges like jruby, jthon, etc. I'd wager money that they will
probably use one of the current open source translations and build on top of
that, maybe gut it like crazy and use it as a foundation. A full rewrite if
php in jvm would probably be extremely difficult timewise.

------
maratd
> Facebook are looking to move PHP on.

Did Google Translate write the article?

------
dreamdu5t
This is all great but... why?

~~~
jeremiep
My reaction exactly. I have great respect for the JVM, but PHP could simply be
replaced by JavaScript for example.

It seems easier to me to port PHP to Rhino or node.js than to bring PHP to the
JVM. Especially considering CoffeeScript, PHP just can't keep up.

~~~
mh-
was this post just written with a JavaScript-buzzword generator?

~~~
erichocean
Yes.js

