Hello!
On the server (nodejs) there is a React which rendrit components and gives them to the client.
If this is done directly (nodejs-browser), then there is no problem.

But I need this scheme:
1. The user requests the page from the application in PHP
2. PHP application in some miraculous way accesses the nodejs reactor
3. React the desired page
4. PHP application receives a standard page from the reagent and gives it to the client.

It turns out the PHP application acts as a proxy between the client and the nodejs with the reactant

How can this be implemented? Where to start, where to dig?
How to link nodejs and php?

  • one
    And you know a lot about perversions. Why do you need to give pages through php? - ThisMan
  • This is necessary for SEO optimization of the SPA application - XYZ
  • Read about curl in php - Kirill Semenov
  • I know what curl is. This option is not suitable, because You will have to send requests via http and the service is highly loaded. I found such a thing github.com/phpv8/v8js , but I can suspect that it will not work. Need help from the person who actually solved such a problem - XYZ
  • @XYZ firstly curl itself is a little bit stupid - it can be readjusted to make it work faster - without this, requests will have hell of a delay. Secondly, you придется слать запросы через http а сервис высоконагруженный - but your http is not friendly with high load? Well, one more option - exec (or a similar pcntl_exec like pcntl_exec ) from PHP - execute, get the result, you want it synchronously, you want asynchronously, except for the web server layer. - Goncharov Alexander

1 answer 1

Through the setting of the web server.

For example: Apache sends certain addresses to PHP (for example, with a specific port), and others to nodejs, to another port. And the nodejs port is closed for access from the outside. As a result, from PHP you send an HTTP request to your server, using curl for example - but on a different port. It turns out the proxy in its pure form.

But you have to be warned - this approach will slow down the work of requests.