PHP to C++ compiler from Facebook - HipHop

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

User avatar
arjan.top
Forum Contributor
Posts: 305
Joined: Sun Oct 14, 2007 4:36 am
Location: Hoče, Slovenia

Re: New PHP from Facebook?

Post by arjan.top »

PCSpectra wrote: LOL
It's why I went out and bought a brand new cutting edge computer system i7 quad core with 12GB of DDR3?? Memory...If Eclipse is running like ahog on this machine I give up on Eclipse ever being a performant IDE. :P
total memory does not matter, you have to tell jvm how much memory heap can take

http://wiki.eclipse.org/FAQ_How_do_I_in ... Eclipse%3F
User avatar
JNettles
Forum Contributor
Posts: 228
Joined: Mon Oct 05, 2009 4:09 pm

Re: PHP to C++ compiler from Facebook - HipHop

Post by JNettles »

I find it refreshing when a private company decides to contribute back to the community. Picture for a moment that you're Facebook - you need a tool. You create a tool for yourself. Your tool works great, so great that you open source it so that others can use it too. I fail to see the downside or the "underhandedness" in all this.
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Re: PHP to C++ compiler from Facebook - HipHop

Post by alex.barylski »

It was internal development for their private use. Do you always develop your internal stuff in the open? now they decided to make it open. why all the negativity?
Haha...I think he is simply bringing to light, the opinions of opposition, nothing more, nothing less. :)

If there was such a thing as a perfect solution or software system, there would never be controversy and how boring would life become?

Cheers,
Alex
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: New PHP from Facebook?

Post by Christopher »

Jenk wrote:Why didn't they do it in the open? They've basically said "This is how we think PHP should be, so here it is." and are now plugging their speed increase in a "HEY GUYS, COME USE OUR PHP INSTEAD!" kind of way, by the looks of it.
First, you are assuming that they knew exactly what they were going to implement when they started. Since they say the software is essentially a Beta and needs much more work, it sounds like they got it to a workable proof of concept (i.e., some part of Facebook can use it) and then released it. Honestly, I have less of a problem with this than the other Facebook libraries which are designed to bring more people and money to Facebook. That is the Microsoft way ... only release things that connect to your software and make you more money. I don't see how opensourcing HipHop makes Facebook a dime. It just potentially makes PHP more powerful. Imagine if the PHP Group figures out a way to integrate it into PHP so you can seamlessly run interpreted or compiled? Or it gets built into APC or something like that? The point of opensource is that people create a solution to their problem and release it, then others can take the software places the original developers weren't interested in or didn't think of.
Jenk wrote:What they should have done was make their intentions known, and then allow some form of input from the community. Not take from a community driven project, hide away, and then unleash a largely unknown and unfamiliar, yet "better" version onto the same community. At least for the beginning it will make anyone who uses this compiler dependent upon the FB devs for support/guidance/etc. Until someone finds a glaring hole, most probably.
Your attitude is that they have taken from rather than have added to a PHP? They don't say it is better. In fact the clearly state the limitations in what they implemented. Yet it is not good enough that they did a good thing by opensourcing it ... you add a "What they should have done" caveat.
Jenk wrote:That is the "dirty takeover". The spotlight has shifted from the PHP team to Facebook, who will no doubt be wearing the "I'm the PHP Daddy" T-shirt.
I think if you had written HipHop in private over the last year -- and opensourced it -- I would buy you that T-Shirt and called you "PHP Daddy". ;)

PS - the consensus in the blogs seems to be that HipHop is not very useful currently except for a very few types of sites, but that perhaps it could be expanded into a more generally useful system. It is PHP 5.2 not 5.3, so work needs to be done to upgrade it. It only supports the extension that Facebook uses, so more work is needed. And it does not support the full language (eval() is mentioned as one thing not supported) so yet again more work.
(#10850)
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: PHP to C++ compiler from Facebook - HipHop

Post by Weirdan »

Sorry to interrupt your highly political discussion on what facebook should and shouldn't do, but has anyone seen the code yet? Their announce points to non-existing project on github.com and that's all... opensourcing the project means providing access to the code, or am I missing something?
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: PHP to C++ compiler from Facebook - HipHop

Post by josh »

They said they'd release it "this evening" and an international day lasts 48hrs. They better hurry up though.
Each day of the week is extinguished, dies, at midnight on the East edge of the International Date Line.
http://home.hiwaay.net/~edbutton/48time.html

:drunk:
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: PHP to C++ compiler from Facebook - HipHop

Post by Benjamin »

I'm not sure it would be possible to compile code inside eval prior to runtime. I don't see how it would be possible to compile what could be dynamic source code.
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: PHP to C++ compiler from Facebook - HipHop

Post by Eran »

They specifically mention that eval is not a part of their compilation engine.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: PHP to C++ compiler from Facebook - HipHop

Post by Christopher »

Yes, some parts of the language (like eval() and create_function()) are not supported. Most people don't use eval() (and shouldn't ;)), so that should not be much of a problem. They mentioned somewhere that they determine the type of variables and convert them to a C++ type. That may effect some code and would require testing/auditing. Probably the fact that it is PHP 5.2 and the lack of support for some extensions would be the biggest hindrances for most developers. And, of course, the fact that the compiled pages are their own web server (bypassing Apache) so some front-end system is needed to send requests to the right place.

Here are some more links to blogs discussing HipHop:

http://terrychay.com/article/hiphop-for ... -php.shtml
http://php100.wordpress.com/2010/02/03/hiphop/
http://www.sitepoint.com/blogs/2010/02/ ... th-hiphop/
(#10850)
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: PHP to C++ compiler from Facebook - HipHop

Post by josh »

I see it as more of use for glue applications. In the article they wrote they normally would just write C++ utilities and call into them from regular PHP. I bet they are only running Hip Hop for certain algorithms. They did mention it is running 90% of facebook's code (I don't know about you but way less than 10% of my code is actually controller code, where regular PHP would be needed). Once you decide to let your regular controllers run in regular PHP you'd just identify certain "services" in your app that could be sped up and compile just those? That's how I look at this tool. Any uses of non standard extensions would probably be encapsulated. I bet they keep certain services running regular PHP for exactly that reason. (facebook fetches 3rd party images, resizes images, etc.. it obviously is using _some_ sort of tool for that other than raw PHP).

For example facebook may call a command line utility for resizing images. Maybe in your app that utility could run regular PHP as opposed to PHP with hip hop.

Have they released any source code yet?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: PHP to C++ compiler from Facebook - HipHop

Post by Christopher »

Watch the video to get a feel for their specific problem and how HipHop solves it.
josh wrote:Have they released any source code yet?
They said "Soon". ;)

I think one important thing to look for is if they find a way to reduce the duplication of effort between PHP and HipHop. For example, they recoded many of the PHP extensions in C++ and insinuated that they fixed some of the tread-safe problems. Will they find a way to use the best code for both? The fact that PHP is C and HipHop is C++ seems to be a real problem.
(#10850)
User avatar
volomike
Forum Regular
Posts: 633
Joined: Wed Jan 16, 2008 9:04 am
Location: Myrtle Beach, South Carolina, USA

Re: PHP to C++ compiler from Facebook - HipHop

Post by volomike »

Here's what I'd like to see. Let's say I have a class Foo, and about 80% of its class methods are the bottleneck of my enormous project. It would be great to be able to use HipHop to compile just this portion of the project into C++, and then somehow load it right back into PHP as an extension. That way, I can stick with PHP for much of the project, but convert my slower classes into C++ and load them as extensions, without needing to know C++.

Can anyone confirm if this is possible?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: PHP to C++ compiler from Facebook - HipHop

Post by Christopher »

volomike wrote:Can anyone confirm if this is possible?
I think you could use HipHop for specific pages, but not for specific classes within an app. Currently, HipHop compiles an executable that is its own webserver. So is runs separately from Apache. If you had a section of your website that was processor intensive the you could serve that section separately.

The other place where HipHop might be of interest is for utilities that are called on the command line. These may have been coded in another language for speed previously. Now with HipHop you can code everything in PHP and get CLI apps that are much faster. Another example might be if you had a separate server that only provided a web service or some data feed -- that might be a candidate for HipHop.

It will be interesting to see if application hosting, such as WordPress, will switch to HipHop. Since they only serve one app it might make sense to compile it.
(#10850)
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: PHP to C++ compiler from Facebook - HipHop

Post by josh »

"Narrow Interfaces" is a good design goal. Your classes should not have too many methods. If you follow this guideline its easy enough to stub out the old PHP class so that it calls the command line with it's inputs, and return's the command line utility's outputs. Coding in narrow interfaces is good for numerous reasons, this being one of them.
User avatar
volomike
Forum Regular
Posts: 633
Joined: Wed Jan 16, 2008 9:04 am
Location: Myrtle Beach, South Carolina, USA

Re: PHP to C++ compiler from Facebook - HipHop

Post by volomike »

First off, I have to admit, Facebook is now phenomenally faster. Not just a little faster -- phenomenally faster. I don't know what they did, whether this is in fact HipHop that has done this, but Facebook is now super fast. Go see for yourself. It actually makes Facebook nice to use rather than something I did every once in a blue moon. (I prefer Twitter.)

But anyway, it would be nice if a product existed that let me write PHP code, and then it would convert to C++ as a PHP-ready extension. However, if none will ever exist, then I guess I'll make do with just outsourcing C++ work to Asian offshoring, should I need it. Another opp. looks to be to make a SOAP/REST service on a dedicated server where the other end is made with HipHop.

Does anyone as old as me remember the days of Visual Basic as the prominent dev platform for business? Anyway, in that platform we used to have competitive companies who would make an extension we could load in that would do things faster than VB could normally handle. So, likewise, it would be great to see something like that for PHP. For instance, a vendor could say, "Use our C++ extension for PHP and we'll give you alternative functions that do many of your common tasks but twice as fast as the original PHP functions."
Post Reply