R
R
Ruslan Karetsky2020-05-04 13:20:59
PHP
Ruslan Karetsky, 2020-05-04 13:20:59

How to update a user's records when another user adds a new record?

An example is entries, comments and messages on VK. If another user sends you a message, a new message is displayed in your private messages. You don't need to refresh the message page. The same goes for posts and comments.
How to implement something like this? I think that database queries every n-seconds is not an efficient solution. What are the other options?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
PQR, 2020-05-06
@PQR

I think that database queries every n-seconds is not an efficient solution.

Depends on the DBMS. If you use the classic MySQL DBMS, you will have to make queries every n seconds.
If you use other systems, such as Redis, you can subscribe to new records and get them reactively. But for this, the application itself (PHP script) must work constantly, which is a separate topic for study.
So the question of "not efficiency" rather lies in a different plane. Vk is a big social network. But how many messages per second are planned for you, specifically in your application? If this is a chat of a local general store and speech is up to hundreds of messages per second or less - MySQL, even on an average hosting, will cope with the scheme "we ask every few seconds, are there any new ones?", And it will be much more efficient in terms of development labor costs,

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question