R
R
RomanSS2016-12-20 09:22:26
PHP
RomanSS, 2016-12-20 09:22:26

How to implement PHP + NodeJS + Socket.IO?

Prompt the correct algorithm for the task.
There is a site, the whole basis is written in php, it is given in a bunch of nginx + apache. When opening a site (php), you need to start a connection with nodejs + socket.io and update the data by events. I do not understand how to make a connection to update the data. This option only comes to mind to run nodejs + socket.io in an iframe in which all events are already sent to the parent.
Conditional code:

<html>
<body>
<h1>Апач создал html документ</h1>
<div>Тут много phpшного кода</div>
<div>Тут постоянно меняющие данные, которые должны меняться по событию socket.io: <span id="count">10</span>
</div>
<div id="chat">Тут может быть чат, сообщения которые тоже приходят от socket.io</div>
</body>
</html>

It is not yet possible to write everything in nodejs, since there is a lot of logic in php, you only need it in separate real-time components. I don’t understand how to connect socket.io so that it accesses the node server and updates the data?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
O
OnYourLips, 2016-12-20
@RomanSS

Don't connect one to the other if you don't want to.
Write and run a websocket server on the node.
You do this with nginx and this server: https://www.nginx.com/blog/websocket-nginx/
Place the client on the page generated by PHP.
Session storage must be available for both technologies. For example Redis.
Feel free to delete Apache, it is not needed for any of the tasks you listed.

N
Nurlan, 2016-12-20
@daager

Not quite what was asked, but https://github.com/wandenberg/nginx-push-stream-module might be useful

W
webman2004, 2016-12-20
@webman2004

In the php code, you connect the javascript client part, which contains the address and port from which to receive data, what to do with it and where to insert it. PHP also has socket support, if you are more accustomed to working with php, use it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question