mysql - How to do scheduled notification and release on time in PHP?
曾经蜡笔没有小新
曾经蜡笔没有小新 2017-05-24 11:33:02
0
9
863

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^_^

曾经蜡笔没有小新
曾经蜡笔没有小新

reply all(9)
仅有的幸福

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

曾经蜡笔没有小新

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.

阿神

Just use the program to keep brushing = =

伊谢尔伦

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

巴扎黑

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

習慣沉默

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.

phpcn_u1582

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. .

phpcn_u1582
websocket 

Or use the workerman swoolescheduled task function

刘奇

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!