Home  >  Q&A  >  body text

前端 - 前后端的数据如何实时对接?

PHP中文网PHP中文网2741 days ago494

reply all(3)I'll reply

  • 阿神

    阿神2017-04-18 10:00:32

    Add machine...

    reply
    0
  • 巴扎黑

    巴扎黑2017-04-18 10:00:32

    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

    reply
    0
  • 黄舟

    黄舟2017-04-18 10:00:32

    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.

    reply
    0
  • Cancelreply