mysql - PHP scheduled task, after an operation is executed, it will time for two hours and then send a text message to the user.
ringa_lee
ringa_lee 2017-05-16 13:04:54
0
9
757

The requirement is that after the user performs an operation, count down for two hours, and then perform another operation at the time

But now there is no way to time these two hours.

Do you have any good ideas

ringa_lee
ringa_lee

ringa_lee

reply all(9)
巴扎黑

My idea is to delay the distribution of a task through the queue, which is to trigger it after 2 hours, and then send a text message in the task.
The following is the document link:

  • Queue delayed distribution

  • SMS notification

PHPzhong

Create a table to store the user’s mobile phone number, text message content, and the time it should be sent.
Users can add a new row of records with one click.
Set a scheduled task, check it every minute, send it when the time is up, and delete the record after sending it

洪涛

Put the name of the task to be executed and the execution time into the redis ordered set, and then check the score of the redis ordered set regularly, and if it is within the range, take out the execution task

曾经蜡笔没有小新

When the user operates, he will definitely save an operation time in the table, and the daemon will keep querying until it sends a text message in two hours

给我你的怀抱

This is the need for timers and message queues. . .

过去多啦不再A梦

Linux uses crontab and the interface system like window has its own customized tasks. Use the scheduled task curl to specify the php file, or use php to execute the php file. In this case, by performing scheduled access every minute (similar to polling), when accessing the PHP file, read the data of the stored data table (conditional two-hour data), you need to throw the data into the queue (to avoid when the amount of data is too large, Sending a large amount of information leads to excessive use of server resources), and finally extract quantitative data from the queue and send the data

仅有的幸福

Use crontab to run the task queue of the database

滿天的星座

You can use a PHP asynchronous framework, such as Workerman or Swoole, to create a timer and execute tasks when you need them! ! !

Ty80

Save the time and event to be triggered, the script will run the data every minute, and execute it when the time is up. It’s the simplest

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