Answer the question
In order to leave comments, you need to log in
How to notify about new records in the database?
There is a server in php, a client in vue, a database in muscle.
How to make notifications to the client about new events in the database? How is it done in the same contact?
For a long time I watched the network table in chrome in developer mode and noticed that every 25 seconds a request was sent to the server (in VK).
But at the same time, if someone sends a message, then it comes instantly .. And one more detail, if you look at the console in the same VK, then there is a record starting server
(now I looked, it seems that there is no such thing already). What does this mean? And it is unlikely that VK sends a request to the server every second. Well, what kind of computing power should be there ..
But back to the main thing, how to make an instant notification?
Well, it's really interesting :)
Answer the question
In order to leave comments, you need to log in
You understand everything correctly. This is called webSockets. I don’t know exactly about php, but for example, python is not asynchronous, and out of the box it does not allow you to notify the client. There are some batteries for this, such as django-channels. Look for php, it should be too. And yes, you put listeners on the client (js), and on the server, through some functions, you do broadcast.
Well, as an option, use Long Polling, there is a lot of material on the network on this topic.
Socket.io. but at the expense of the stream of new records, there is only one database that implemented this, it is called
rethink
See how events are implemented in Laravel. There, the process works like this:
When you write through the model to the database, the "saved" event fires. And this is somehow connected with memcache. And memcache can be connected to websocket. And instant notifications work
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question