Pergunta

I am confused about using nodejs. I need help in it. All I want to do is to create a PHP MySql Application that shows sales information of any office. I want the data to be in real time. That is whenever a change is made to the database the result is displayed into the web page without page refresh. After doing a research, I found that nodejs and socketio can do this work, but I'm not sure how to implement this. I'm using a XAMPP localhost in office. I really need a help on this issue. Thanks in advance.

Foi útil?

Solução

You may want to consider the following approach: from within your PHP, do a push of data via an outgoing HTTP/POST to a WebSocket server. The WebSocket server maintains the real-time connections to your JavaScript frontends. Upon receiving data, the JS updates the UI. When your PHP app is a classic one (not a single-page web app), that means new page loads when the user navigates through your Web app. Which in turn means loosing the WS connection and reestablishing it.

These are some challenges:

  • You need not only a WebSocket server, but on top of that some message brokering (publish & subscribe).
  • That server needs to have a HTTP/POST (REST) endpoint for your PHP to push to.

If you want to go with a hosted cloud service, I'd recommend looking at pusher.com.

If you want to get going fast, host your own stuff, but don't want to build/develop the functionality, you may look at http://www.tavendo.de/webmq Here is an example: https://github.com/tavendo/WebMQConnectPHP/tree/master/examples/basic

Disclosure: I work for Tavendo.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top