前端 - 前后端的数据如何实时对接?
PHP中文网
PHP中文网 2017-04-18 09:58:32
0
3
535
PHP中文网
PHP中文网

认证高级PHP讲师

reply all(3)
阿神

Add machine...

巴扎黑

As long as it is a round robin, there will definitely be this time interval.
Mysql does not seem to have a data monitoring mechanism
You can add a layer of redis or mq in front
1. Add a task to the front end
2. Write the task to redis/mq and write it to mysql
3. The backend monitors redis/mq and gets the task Execute, update mysql after execution is completed

Needless to say, mq is all used to monitor
redis using pubsub.
redis pubsub is very simple to use. http://redis.cn/commands/pubs...
In this way, the backend can also perform tasks concurrently

黄舟

The front-end should not be able to directly write to the database. The front-end should send the request, and the back-end will execute the front-end's request. Then after the back-end completes the write operation to the database, it can directly send another message requesting the execution of the task.
Of course, this message can also be initiated by the front-end after the front-end receives the successful writing message. However, this seems unreasonable and wastes server resources.
In this way, the way the backend performs tasks should not be polling, but should be changed to listening for responses. When the execution request of a new task is monitored, the data is fetched from the database and added to the task queue.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template