D
D
Dmitry Ivanov2017-02-06 15:28:16
MySQL
Dmitry Ivanov, 2017-02-06 15:28:16

What is the best way to update data from MySQL on the site in real time?

Good afternoon!

I'm doing an auction. I write in yii2 (but it doesn't matter). It is necessary to display the last 5 bets from the database in real time on the page. Those. receive data at least once per second.
There is an old, long-tested next option: once a second, make an ajax request to the server, which retrieves the last 5 records from the table.

Perhaps now there is a better modern option than "hammering" the server with ajax requests?

There is, it would be great to show an example.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
M
Maxim Timofeev, 2017-02-06
@vyrtime

Yes, there is such a method, it is called sockets
Here is an article on the topic of yii and sockets:
http://satirics.net/wp/2015/09/22/websock-creation...

T
ThunderCat, 2017-02-06
@ThunderCat

As they wrote - sockets, and there is an option with long polling, for example here and here , and I would look more at the comments in the first article.

A
Alexander Chernykh, 2017-02-06
@sashkets

through an intermediate memcache or redis database (redis can also sync to disk), and sync redis/memecahe with mysql every 5 minutes

D
Dmitry Evgrafovich, 2017-02-06
@Tantacula

We need websockets. Create one channel for each lot, or one channel for all lots - as you prefer. Clients subscribe to channels, then when someone makes a bet, it is processed on the server, entered into the database, after which the data about this rate is sent by the server to the channel and all subscribers receive this update. There is no need to send data every second - this is an unnecessary load, only when a new rate appears. For websockets, I would personally recommend centrifugo, it consumes very few resources and is fast. There will be no code example for yii - I didn't work with it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question