How to notify about new records in the database?

There is a server on PHP, the client is at vue, DB on the muscle.

How to make alert the client about new events in the database? As it is made from the same contact?

A long table watching the network in chrome in developer mode and only noticed that every 25 seconds a request is sent to the server (in VC).

But if someone sends a message, it comes immediately.. And one more thing, if you look at the console in the same VC, then there is a record starting server (who looked already like no such). What does it mean? And hardly VK every second sends a request to the server. Well this is what sort of processing power should stand..

But back to the main how to make instant notification?

You really wonder what is :)
ce8420e364ce485fb2939ecda7c00832.png
June 27th 19 at 15:20
6 answers
June 27th 19 at 15:22
Solution
You are all correct you know. It's called webSocket-AMI. Not sure about PHP, but for example, python - mode is not asynchronous and it's from a box does not allow to inform the client. To do this, there are some batteries, such as django-channels. Search for PHP must be too. And Yes, you put listeners on the client(js) and server, by certain functions of do broadcast.
June 27th 19 at 15:24
Solution
To the question you actually answered - for your problem use WebSocket. I assume that every 25 seconds from your example - just a service message 'I'm still here.' From PHP websocket did not work, just because of the concept and architecture of language. There is a Ratchet, you can try to work with him.
June 27th 19 at 15:26
Well, as an option to use Long Polling, the web is a lot of material on this topic.
The inhabitants of 2017 convey greetings to the ancestors. We have AJAX there fifteen years, and recently (5-6 years ago) and still websocket's invented. - Austen.Thompson53 commented on June 27th 19 at 15:29
: do you know what is Long Polling? Why using pure ajax Postojna to disturb the server sozdaval a load on it when you can nedelat. Long Polling is used even the guys from VK https://vk.com/dev/using_longpoll - jermaine_Kub67 commented on June 27th 19 at 15:32
: Ten years ago we even used it. Now I even became a little bit curious, what are the advantages of myspace found in long pooling except that the support for older browsers. I would understand if it was as a fallback, but why make it the primary means of delivery is a mystery to me. - Austen.Thompson53 commented on June 27th 19 at 15:35
: support drevnyuchy browsers. - mario commented on June 27th 19 at 15:38
June 27th 19 at 15:28
to implement something like observer pattern
June 27th 19 at 15:30
Socket.io. but on account of the stream of new records, there is only one database, which is implemented, is called rethink
With relationto need a trigger module to trigger external events, and even still
June 27th 19 at 15:32
View how to implement events in Larval. The process works like this:
When you record through the model to the database srabatyvaet event "saved". But it's something to do with memcache. While memcache can be associated with websocket. And instant notifications are working

Find more questions by tags JavaScriptPHPVue.jsMySQL