Socket.io for real time application

后端 未结 2 2022
失恋的感觉
失恋的感觉 2021-02-04 18:40

So I have another project that I built a few months ago. It currently uses jquery with ajax and makes a call to a php script every 30 seconds. The php script queries mysql and p

2条回答
  •  佛祖请我去吃肉
    2021-02-04 19:00

    Would socket.io be the answer to this?

    My answer is that socket.io / node.js is much better at dealing with real-time applications then PHP in the current form.

    Then on the client side just have a function that calls the server socket script like every second?

    In node.js you should not poll ask for the information, but instead you should have the information pushed(use redis pubsub or node.js events for that) to you. I advice you to have a look at a pubsub snippet from me on stackoverflow.com to explain myself a little bit. For the code to work you will need to install socket.io 0.6.x(0.6.18) because the latest socket.io 0.7.x has a slightly different API.

    If so would there be a concern with this process if I ran it every second with regards to server resources?

    Like I said before use pubsub semantics. You could for example use:

    • redis pubsub
    • events

提交回复
热议问题