G
G
Galdar Turin2019-12-23 11:03:48
PHP
Galdar Turin, 2019-12-23 11:03:48

How to implement data exchange between Node js and php?

There is socket io on nodejs, everything works well, but there was a need for socket`e to execute php scripts. There is a part of php scripts that can either be rewritten to node js or tied to socket. Of course, I would like to tie them up with socket. But here's how to do it, since the socket is asynchronous, it works with memory, it is possible to tie up synchronous php scripts and store them in memory until the end of their execution. And then what will be right and is it even possible?
---
1. Create a socket io in PHP and communicate between node js and php
or
2. Install a library to run PHP in node js
---
- In the first case, this is an idea that I don't know how to do yet.
-In the second I find libraries, but for the most part they just have a call, but there is no data exchange between node and php. Tobish, I can run a php or node file, without a return response in the form of json.
I would like to get an answer on how best to do this, advice. Any scheme for building this system, in which node js socket io can start php and wait for a response.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
A
abberati, 2019-12-23
@Galdar

PHP and node need to communicate over http.

I
Ivan Shumov, 2019-12-23
@inoise

Look at ratchet or workerman. I like the socket node better, but then it would be a lot of fun to jump around in matters of communication and isolation

D
Dmitry Belyaev, 2019-12-23
@bingo347

In my opinion, the most correct thing is to make requests to php-fpm from the node. It communicates over the rather standardized fast-cgi protocol, for which you can find a client on npm, for example here: https://www.npmjs.com/package/fastcgi-client

V
Vladimir Korotenko, 2019-12-23
@firedragon

Use as already said http / s
or any queue, for example this one https://www.rabbitmq.com/
Ps Yes, at least get a separate plate in the database
and write tasks to it.
jobid | job status | job parameters | jobresult
------------------------------------------------- -----
42 | pending | {"param": "paramvalue"} |23
43 | progress | {"param": "paramvalue"} | 99
44 | Complite | {"param": "paramvalue"} | 999

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question