Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable Angular Universal with a PHP backend #281

Closed
jeffwhelpley opened this issue Feb 24, 2016 · 54 comments
Closed

Enable Angular Universal with a PHP backend #281

jeffwhelpley opened this issue Feb 24, 2016 · 54 comments

Comments

@jeffwhelpley
Copy link
Contributor

This should be possible, but a lot more time needed to experiment and create a proof of concept.

@tbosch
Copy link
Contributor

tbosch commented Feb 25, 2016

I have a design for this already.
See
https://docs.google.com/document/d/1a3LDFEi6xV9vNNZxjoRwIw-Z3pgj_HAZXCJe8-gkAeA/edit

On Tue, Feb 23, 2016 at 5:58 PM Jeff Whelpley notifications@github.com
wrote:

This should be possible, but a lot more time needed to experiment and
create a proof of concept.


Reply to this email directly or view it on GitHub
#281.

@jeffwhelpley
Copy link
Contributor Author

Sweet! Thanks for the link.

@b-strauss
Copy link

Hi, I would like to take a look at this. My idea is to write a PHP extension, that uses PHP-CPP to embed JXcore. JXcore is a node.js fork, unfortunately from an older branch (v0.10.40), but it claims to be easily embeddable. Is angular using any features that are incompatible with this node version? I'm no c++ expert, and I have no idea when I will have some first results and how the performance would be, but the possible simplicity of just adding a file to your php extension folder seems worth a try. If nothing speaks against it I will start working on it. The result would probably be usable with any javascript code, not only angular.

@jeffwhelpley
Copy link
Contributor Author

@manekinekko I thought I remembered you saying there is another approach for PHP integration than the one @b-strauss is suggesting, right?

@jeffwhelpley
Copy link
Contributor Author

But, FYI, @b-strauss it is not that ideal being on that old a version of node. v0.10.x is pretty stable so it may work, but we should check to see if there are other options if possible.

@manekinekko
Copy link
Contributor

@jeffwhelpley I was referring to https://github.com/phpv8/v8js

@b-strauss I am afraid v0.10.x is not compatible with the build system of Angular2 but I may be wrong. I just run the Universal starter with node v0.10.42 I everything just blew up. See screenshots.

image

Beside the version of NPM shipped with Node v0.10.42 seems to be deprecated.

If we can get the latest version of Node running with JXCore, that would be an interesting solution to explore.

@b-strauss
Copy link

@manekinekko It looks like they are working on Node v4 integration. jxcore/jxcore#535

Maybe node.js can directly be compiled into a library? Seems like atom does this. See:
nodejs/node#2953

@b-strauss
Copy link

I just realized the PHP-CPP people have also written a PHP-JS bridge.

http://www.php-javascript.com/

@manekinekko
Copy link
Contributor

@b-strauss thanks for your feedbacks and researches.
Good find for php-js, it looks like Nashorn for Java 8. Funny ^^

IMHO, I think we shouldn't be focusing on writing a nodejs/v8 wrapper for PHP. We should use whatever the industry is using. We could however provide an extension for PHP that acts like a bridge for Angular2 Universal (that's the big picture). So, to me, we would explore the following solutions:

  1. v8js
  2. jxcore (node v4+)
  3. php-javascript

Remember that we want the developer to just drop the Universal deps into her/his projects and things would work automagically. That'd be the ideal solution.

@jeffwhelpley @tbosch your thoughts?

@jeffwhelpley
Copy link
Contributor Author

I have no strong opinions on this as long as the implementation fits into the common standards we put in place. I don't have a ton of experience with PHP so likely we need someone to take the lead on this.

@b-strauss
Copy link

I was just able to render a simple "hello world" from a js file to the php output with v8js and its pre-built binaries for windows.

The server response time was between 90 and 140 milliseconds on my windows dell laptop. A simple php "hello world" takes about 5 to 15 milliseconds on my machine. I don't think this would be a problem if one caches the generated output on the php side.

I will take some time to write a few php and js helper classes in the next days to send data between the two and handle module path resolution.

Can someone point me to a universal example app that I could use to test this?

@jeffbcross jeffbcross modified the milestone: Beta.0 Mar 18, 2016
@jeffwhelpley
Copy link
Contributor Author

Alright, so the PHP integration to Universal has been a back burner item for a little while but let's work on making this legit. If you just want status updates on this effort, watch this issue. If you can be more heavily involved, email me at jeff at gethuman dot com. I am in the process of organizing a quick meeting among all interested parties.

@mrjmd
Copy link

mrjmd commented May 21, 2016

@jeffwhelpley I have been doing a little bit of work on this already and it was discussed a fair amount at ngconf a couple of weeks ago. Dropping you an email.

@TheLarkInn
Copy link
Member

@mrjmd is that angular2-drupal repo implementing universal? I have a few devs on my team that are interested in contributing.

@TheLarkInn
Copy link
Member

Ive found that with V8js you have to define your own module loading system in PHP. I reached out to them and was directed to this gist (if this helps anyone).

https://gist.github.com/stesie/c9143b98355295420470#file-example-php-L12

@john-landgrave
Copy link

I see this was last touched 7 months ago, is this being handled somewhere else (like its own repo)?

@jeffwhelpley
Copy link
Contributor Author

@john-landgrave the prototype was built in a private repo. Much of the universal code is moving to core now, so this effort has been put on hold until that is complete.

@b-strauss
Copy link

@john-landgrave

I experimented with v8js, which is a PHP extension that includes the v8 engine. I was able to render a simple hello world string sent from js to php (90 to 140 ms response time). This basically works, although it was slower than a native php string (5 to 15 ms response time). v8js requires a custom module loader implemented via callbacks on the PHP side. I did not go so far as to implement that.

Other tools were investigated, but led nowhere.

@john-landgrave
Copy link

@jeffwhelpley and @b-strauss

Thanks for the responses guys! We're very interested in starting some work on using Angular 2+ as the basis for some WordPress themes in order to step up our offerings, but obviously the SEO impact of Angular Universal is a pretty big necessity. I'll keep an eye on news around Angular Universal and PHP.

@maximumver
Copy link

yeah, 26% of web is powered by wordpress, not even saying that PHP is realy popular too, we need Angular Universal on PHP very badly.

@drarko
Copy link

drarko commented Mar 29, 2017

Any updates on this? Can I help with something? I have experience with PHP and its modules.
I will glad to participate on this project :)

@bonatoc
Copy link

bonatoc commented Mar 30, 2017

... so do I. But we need a roadmap, and a short desc of what is available, what needs to be done. Who can provide this info? Where can we start?

@killrazor
Copy link

"@jeffwhelpley
jeffwhelpley
commented 11 months ago

Alright, so the PHP integration to Universal has been a back burner item for a little while but let's work on making this legit. If you just want status updates on this effort, watch this issue. If you can be more heavily involved, email me at jeff at gethuman dot com. I am in the process of organizing a quick meeting among all interested parties"

@mrjmd
Copy link

mrjmd commented Mar 30, 2017

This effort never really got off the ground. We had one Google hangout after ngconf last year but I think the key need was someone to champion this issue, and no one really stepped up to do that.

Here's my blog post about my initial attempts at a v8js hello world from last year:

http://mrjmd.com/angular-universal-and-php-first-adventures-v8js

I think part of what I've struggled with is the specific use case for this. Since from a cursory investigation the level of effort does not appear to be low, in my mind the use case needs to be broad / important enough to justify that effort. I'm not entirely convinced it is.

If you already have a PHP CMS like WordPress or Drupal rendering part of the page server side, can't you move your SEO concerns into the CMS? And if you're building a full headless / decoupled Angular app with a PHP API for your data store, you can use Universal without issue, correct?

All that said, ngconf is next week and if people in this thread will be there and think this is an important issue to move forward I'd be interested in being involved in further discussion about it.

@jeffwhelpley
Copy link
Contributor Author

Greetings! Sorry for the lack of updates. The effort did indeed get derailed because shortly after ng-conf we decided that a major refactoring was needed before we opened Universal up to non-JS back ends. That refactoring took much longer than expected for a variety of reasons, but is now complete with the release of Angular v4. As you can see from this:

https://github.com/angular/universal#roadmap

We are back on the road toward integration with non-JS back ends starting with Java. PHP is on the list for Angular 5.0+, but the key thing to look out for is the Java integration because the approach being taken is one where we will have what is hopefully a generic integration for any type of back end. Once that is complete (ideally with v 4.1+), we can fire the PHP effort back up to try to build the PHP interface on top of that generic integration.

@vikerman pls correct anything I said that is invalid and add your 2 cents.

@vikerman
Copy link
Contributor

vikerman commented Mar 31, 2017

We are focusing on getting the Java backend going for the next 3 months - but if someone in the community is willing to step up we can definitely work out a similar solution for PHP in parallel.

The easiest way to get this going at this point is to have a PHP<->Node.JS bridge. This is the model ASP.NET has been using. Difficulties with using just V8 - Even if we have some bundling solution to avoid module loading issues, trying to get an Angular application on vanilla V8 and having the right polyfills for node event loop and getting all these to work with Zone.js will be challenging.

@mrjmd
Copy link

mrjmd commented Mar 31, 2017

@jeffwhelpley Thanks for the update! @vikerman I am interested in being involved, it would definitely help for me to follow along with the Java integration work as it happens so I have a better sense of what will be involved.

@killrazor
Copy link

killrazor commented Apr 7, 2017 via email

@b-strauss
Copy link

b-strauss commented Apr 7, 2017

@jeffwhelpley @killrazor

v8js has no nodejs runtime, it only includes V8. If you want to do anything on the javascript side (loading modules, http-requests, etc), you have to do that on the php side and send it to v8js.

@mrjmd
Copy link

mrjmd commented Apr 7, 2017

@killrazor I am wondering the same thing. My understanding was that one of the primary use cases for going this route was the ability to run Universal in scenarios where you would not have nodejs in production.

But from my read of @vikerman's comment above it sounds like the difficulties of going down the pure V8 road may not be worth the effort, even with the module loading example @TheLarkInn linked.

@jeffwhelpley
Copy link
Contributor Author

Sorry, I updated my comment. I made an incorrect assumption about how v8js works. It looks like it does actually work in the same process without spinning up a node server. My main point, though, was that the tricky part is coming up with the protocol. You can check out the .NET implementation to get a sense of the types of things that are needed:

https://github.com/aspnet/JavaScriptServices

@b-strauss
Copy link

I'm experimenting with socket connections (https://github.com/b-strauss/php-node-bridge). Unfortunately the response time is 2.33 seconds. 😐

@jeffwhelpley
Copy link
Contributor Author

That doesn't sound right. A basic node.js API server call should respond in like 10ms. Where is that time coming from?

@b-strauss
Copy link

The problem doesn't seem to be the socket request. The problem is the \ElephantIO\Client initialization at https://github.com/b-strauss/php-node-bridge/blob/master/node-bridge/src/Client.php#L26. Unfortunately ElephantIO is not being developed any more, and I could not find any other library working with socket.io. Maybe someone could checkout the repo and test it on their machine?

@fxck
Copy link

fxck commented May 18, 2017

Any updates on this?

@thorsten
Copy link

I would like to help.

@manekinekko
Copy link
Contributor

@vikerman @MarkPieszak do we have any update on this?

@kenji-1996
Copy link

As someone who is using traditional hosting and wanting to know the best way to go about designing an application using angular but maintaining SEO and things I was wondering if something like this would be the solution (when/if it eventually gets done) or is there some other direction i should persue for this outcome?

@fxck
Copy link

fxck commented Nov 2, 2017

If you care mainly about seo, use prerender.io or any other similar service, just like you would with angularjs.

@angelfraga
Copy link

https://angular.io/features 'section speed & performance' subsection 'universal':

Serve the first view of your application on node.js, .NET, PHP, and other servers for near-instant rendering in just HTML and CSS. Also paves the way for sites that optimize for SEO.

But PHP it is not implemented yet in spite of the mostly web sites are build on PHP. 🤔

Third party services aren't the solution. Are there another ideas in progress?

@bonatoc
Copy link

bonatoc commented Nov 15, 2017

From this page :

V8Js is a project that allows you to install the V8 JavaScript runtime within a PHP environment and create such a sandbox. But until Vue version 2.5.0, this was still not adequate as Vue SSR required certain Node.js APIs to run correctly. The recent update has made sure the server renderer is now “environment agnostic” and can therefore be run in Node.js, V8Js, Nashorn etc.

I guess the way it is approached here should work for Angular (and Laravel). It's mainly webpack processing and building.

@krazygit
Copy link

Any news ?

@NgYueHong
Copy link

This should be Angular 6 main priority feature to develop.

@CaerusKaru CaerusKaru added this to the Backlog milestone Mar 7, 2018
@VladSuciu76
Copy link

Any news?

@vsimeonoff
Copy link

It will be very nice feature if we have Angular Universal working with PHP.

@wikycheng
Copy link

Any news for Angular server rendering with PHP?

@eddieedease
Copy link

Angular Univeral is written to work with a node.js back-end. So, when we want a php universal variant it needs to come from an 'adapter' library for PHP of nodejs.
Just saying this because I get the feeling some people expect an PHP-backend only version. (So skipping nodejs entirely). I could be wrong but I think that's another beast all together.
If it is for SEO reasons, maybe look for other solutions?

@wikycheng
Copy link

@eddieedease Any suggestion to solve the SEO Issues with Angular? Except using third party services such as prerender io. Thanks.

@kenji-1996
Copy link

I think for alot of people the want for a PHP angular universal is to be able to run angular universal setup on standard shared webhosting that doesnt usually support node backend or SSH access etc.

For those of you in that area like I was, I suggest finding a cheap VPS and setting it all up yourself (The node, w/ a reverse proxy etc) because it will make your life easier and you will get sysadmin experience
not to mention its way cheaper

@Toxicable
Copy link

Closed in favour of #1000

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 4, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests