I am trying to understand how to correctly implement the notification system on the site, like VC - the user who is affected by the event gets a notification about a new message in the chat, comments under some post, etc.
I know that VC is done using long polling. I also know that this can be done using websocket and Server-sent events. I tried to find examples of implementing similar in PHP and fell into a stupor. The main aspect of event handlers (be it long polling or SSE) is checking for changes in the database in an infinite while (true), but in my opinion, if in an infinitely loop you constantly peg with database queries, then sooner or later with a larger number of users, the database is stupid will not stand it.
This is the question, how to correctly implement these alerts and similar mechanisms with the DB + long polling (websocket, SSE) without endless polls to the database? Maybe I'm missing something in this moment.
I also heard about the method of creating a separate table for events, which is also constantly polled, and if records appear there, the server sends a message and deletes the record from the database, but again, these are endless queries to the database.

  • one
    It is necessary not to send requests from yourself in a cycle whether the changes have appeared, but rather to receive notification of changes to yourself. This is done without the participation of the database at all pubsub-server (Redis, RabbitMQ and the like), but how is it all to be friends with php, I do not know - andreymal
  • You can see how it works in the same Laravel, there it is done using notifications (notifications) and echo service ( Daniel Protopopov)

0