M
M
Mikhail Solovyov2016-11-23 21:39:54
PHP
Mikhail Solovyov, 2016-11-23 21:39:54

Node.js and php - how to combine?

Hello. I need to somehow monitor the information that is added to the database in real time. AJAX is not an option because there will be a lot of requests, and it seems to me that polling every n seconds is not optimal, given that if there is a large attendance, each will have its own request.
I need to have one request for everyone and in real time.

I came to the conclusion that I need to resort to node.js, but here another task arises - the site itself is written in php. Can these two things be combined somehow? I use the CodeIgniter 3 framework.
I have never worked with node.js, so I don’t know what will come of it.
Or are there other options? I would be very grateful for your help)

Answer the question

In order to leave comments, you need to log in

7 answer(s)
A
Artem Kislenko, 2016-11-24
@Mihairu

I was in a similar situation, I installed a socket server and a separate site in php. It turned out that the socket server loaded the system very heavily (there were problems with DDOS).
In the end, I decided, because. the data is the same for everyone, just set the cron script to write everything to a json file, and then with the usual ajax it was taken once a second, the file was given to nginx, i.e. it was not necessary to raise any backend processes, as a result, the load dropped significantly.
And with node - there will be a problem (if you have not worked with it before) to expand so that it works on all cores (or on half) and in order for the sockets to correctly send information, you will need to use some kind of message broker.
Don't use node in this situation, I would advise you to.

D
DuD, 2016-11-23
@DuD

Install Redis and cron it with the latest data from the database. Take from the radish with the same php. The meaning of producing a zoo of technologies is not clear.

I
Ivan, 2016-11-23
@LiguidCool

Rave. What is the difference in the interaction of php and node with the database? When you answer the question, you will understand the absurdity of the task.

Сергей, 2016-11-23
@begemot_sun

Могу сделать веб-сокет сервер, с http API.
Т.о. веб-клиенты будут цепляться по вебсокету к серверу, а ваша какая-то часть будет использовать API чтобы пославть какие-то сообщения клиентам, адресно или броадкастом.

P
Philipp, 2016-11-23
@zoonman

Возьмите socketo.me и добавьте веб-сокеты на страницу. Вместо zeroMQ можно redis pub/sub прикрутить, если хотите.

Z
zTrue, 2016-11-23
@zTrue

Риал тайм уведомления с node.js + php
1) Комет сервер на ноде (для простоты можно заюзать socket.io)
2) При обновлении данных стучать в комет сервер из php скрипта (лучше асинхронно, можно заюзать очереди типа beanstalk). Это не мониторинг БД, но если у Вас как-то упорядоченно обновляются данные в БД, то вряд ли это станет проблемой.
3) При стуке в comet из PHP слать уведомления клиентам

A
akzhan, 2016-11-24
@akzhan

Вам не нужен Node для этого. Если точнее, можно использовать что угодно.
https://habrahabr.ru/post/209864/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question