A
A
Artem00712017-04-07 23:30:57
PHP
Artem0071, 2017-04-07 23:30:57

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 :)
ce8420e364ce485fb2939ecda7c00832.png

Answer the question

In order to leave comments, you need to log in

5 answer(s)
Y
Yeldos Adetbekov, 2017-04-07
@Artem0071

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.

V
vopross, 2017-04-07
@vopross

Well, as an option, use Long Polling, there is a lot of material on the network on this topic.

A
Andrew, 2017-04-08
@undefined_title

implement something like the observer pattern

V
Vitaly, 2017-04-08
@vshvydky

Socket.io. but at the expense of the stream of new records, there is only one database that implemented this, it is called
rethink

D
Dastan, 2017-04-18
@dastiw1

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 question

Ask a Question

731 491 924 answers to any question