M
M
ML2016-05-11 13:02:06
PHP
ML, 2016-05-11 13:02:06

How to properly configure nodeJs for php application?

The site is written in php, you need to fasten node.js.
I have several options for how this can be done.
Create a port for the domain, like "domain.com:1337" and connect it via curl in php
Or via iframe, but something tells me that no one does this.
How to make the connection correctly and protect yourself from hacking the server?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Super User, 2016-05-11
@staffID

There is such a thing called DNode : https://github.com/bergie/dnode-php
Another theoretical option is to use RabbitMQ . It is just made in order to connect two systems that are not compatible with each other.
In general, the simplest option is the one that was proposed in the body of the question, that is, hang a node on a localhost on some port and knock on it with a curl. If the port is closed for http requests, then there should be no security issues.

N
Nazar Mokrinsky, 2016-05-11
@nazarpc

Judging by what we managed to find out in the comments, you don’t need PHP or Node.js, it’s actually about instant message delivery, depending on what happens on the server.
Your best bet (given the prevalence of support in popular browsers) is WebSockets.
WebSockets can be implemented in Node.js, for example, I once used the nodejs-websocket NPM package .
You can also implement a WebSockets server in PHP, which is already convenient (it can be useful for code reuse and, in general, implementing everything within a single stack). For PHP, one popular implementation is Ratchet .
If you have something happening on the site (which already exists in PHP) and you want to send a message to the client via WebSockets, I would recommend connecting to the same WebSockets server (no matter what it is written in) through the Pawl library (part of the project Ratchet), which is a WebSockets client and is written in PHP (but you need to somehow distinguish between internal requests from the server and external requests from clients, for this you can enter some secret token in server messages).
Now the second part, about the port. In fact, if you control the server, you can hang everything on one external port, and inside Nginx it will figure out where to send the request - if necessary, it will send it to the PHP interpreter, and if it is a WebSockets connection, it will switch the protocol to WebSockets. You can see how this is implemented in my framework using the example of the Nginx config here: https://github.com/nazar-pc/CleverStyle-CMS/wiki/N... See where /WebSockets location.
And I highly recommend that you figure out how Node.js differs from PHP from WebSockets from AJAX in order to ask more specific questions in the future and the implementation will not work otherwise.

F
fetis26, 2016-05-11
@fetis26

There is such a thing
php.net/manual/en/intro.v8js.php

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question