Long polling - Message system

前端 未结 4 864
夕颜
夕颜 2021-02-02 01:06

I\'m looking into doing some long polling with jQuery and PHP for a message system. I\'m curious to know the best/most efficient way to achieve this. I\'m basing is off this Sim

4条回答
  •  野的像风
    2021-02-02 01:48

    Instead of creating a column named last_checked, you could create a column called: checked. If you save all messages in the database, you could update the field in the database. Example:

    1. User 1 sends User 2 a message.
    2. PHP receives the message using the long-polling system and saves the message in a table.
    3. User 2, when online, would send a signal to the server, notifying the server that User 1 is ready to receive messages
    4. The server checks the table for all messages that are not 'checked' and returns them.

提交回复
热议问题