search

Home  >  Q&A  >  body text

mysql - How to do scheduled notification and release on time in PHP?

Requirements/scenarios:

  1. For example, set an article to be published on 2018-5-22 13:51:16.

  2. Notify me in three days.

  3. Messages are automatically deleted after expiration.

……

Waiting for this kind of demand, it is to do something automatically at a certain point in time. This seems to have nothing to do with the queue. Does it require some middleware or other time, or a resident process or something.

My understanding is that the tasks to be done are placed in a table row by row, and then a process is continuously refreshed. The tasks that meet the time node are taken out for execution. Is this the idea?

Want to know what the mature solution for this scenario is made of?

Thank you^_^

曾经蜡笔没有小新曾经蜡笔没有小新2746 days ago873

reply all(9)I'll reply

  • 仅有的幸福

    仅有的幸福2017-05-24 11:35:02

    Use delayed tasks, https://github.com/ouqiang/go...

    How to implement delayed tasks

    1. Implement it yourself, use time wheel or small root pile

    2. Use redis keyspace notification

    3. beanstalkd

    reply
    0
  • 曾经蜡笔没有小新

    曾经蜡笔没有小新2017-05-24 11:35:02

    The main thing of the poster should be DelayQueue, which is the delayed message queue service. For specific scenarios, please refer to:
    1. Taobao’s automatic order cancellation service
    2. Ele.me’s order SMS notification service, etc.
    Implement Timer based on wait/notify method.

    reply
    0
  • 阿神

    阿神2017-05-24 11:35:02

    Just use the program to keep brushing = =

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-05-24 11:35:02

    You can use crontab scheduled tasks to solve it, and you can design the Php interface to be called every day, hour, and minute.

    reply
    0
  • 巴扎黑

    巴扎黑2017-05-24 11:35:02

    Add a time field, and then make relevant judgments at the model layer

    reply
    0
  • 習慣沉默

    習慣沉默2017-05-24 11:35:02

    Program brushing, but database pressure must be considered.
    You can push all tasks into the queue, take the script out of the queue in an infinite loop, compare the time points, and throw the tasks to the execution module when it arrives. If the time is not up, continue to the other side and push into the queue.

    Two queues. For example, queue to be executed: tasteList; queue to be executed immediately: runList.
    Divide task retrieval and task execution into different processes:
    1. Task retrieval: The script pops tasks from tasteList in a loop, determines the time point, and pushes the task to the runList queue when the time is up. If it is not enough, continue to push it into the tasteList;
    2. Execute the task: loop through the runList to pop, and execute it as soon as there is a task.

    When the volume is large, you can just open a few processes as needed, and there is no need to think about repeating the execution.

    reply
    0
  • phpcn_u1582

    phpcn_u15822017-05-24 11:35:02

    Just use the system’s scheduled task function to trigger a script. You can decide what the script does and how to do it. You can also refer to the answer above.
    Generally speaking, a high-frequency script is enough (for example, once a minute or once every 5 minutes). You can judge the time within the script and then call tasks with different frequencies. This is much easier to manage than setting up scheduled tasks for each frequency script separately. .

    reply
    0
  • phpcn_u1582

    phpcn_u15822017-05-24 11:35:02

    websocket 

    Or use the workerman swoolescheduled task function

    reply
    0
  • 怪我咯

    怪我咯2017-05-24 11:35:02

    That is, you save the data and then make a script to continuously detect it. . For example, test once every 1 minute

    reply
    0
  • Cancelreply