Answer the question
In order to leave comments, you need to log in
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
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.
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.
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.
Могу сделать веб-сокет сервер, с http API.
Т.о. веб-клиенты будут цепляться по вебсокету к серверу, а ваша какая-то часть будет использовать API чтобы пославть какие-то сообщения клиентам, адресно или броадкастом.
Возьмите socketo.me и добавьте веб-сокеты на страницу. Вместо zeroMQ можно redis pub/sub прикрутить, если хотите.
Риал тайм уведомления с node.js + php
1) Комет сервер на ноде (для простоты можно заюзать socket.io)
2) При обновлении данных стучать в комет сервер из php скрипта (лучше асинхронно, можно заюзать очереди типа beanstalk). Это не мониторинг БД, но если у Вас как-то упорядоченно обновляются данные в БД, то вряд ли это станет проблемой.
3) При стуке в comet из PHP слать уведомления клиентам
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question