Now I have encountered the following problem: {code:
User A logs on to the background and sets A scheduled task to be executed at every morning. User B logs on to the background and sets A scheduled task to be executed at every night. User C... how to design a web system user, not an operating system user.
Reply content:
Now we have a problem:
User A logs on to the background and sets A scheduled task to be executed at every morning. User B logs on to the background and sets A scheduled task to be executed at every night. User C... how to design a web system user, not an operating system user.
After you set a scheduled task, the background logic sends the scheduled taskcrontab
, Usecrontab
To periodically execute user tasks.
Https://github.com/osgochina/swoole-crontab
The swoole-based Timer Program supports second-level processing.
Asynchronous multi-process processing.
Fully compatible with crontab syntax and supports Second Configuration
Use swoole extension 1.7.9-stable and later. Swoole
The general practice is to use crontab or daemon to scan the data in the background after you set a scheduled task (as long as the field mark becomes invalid, activate and execute qualified tasks.
I can see that you have tagged php. php can use the pcntl extension to implement pure php timer tasks. Currently, php only supports triggering in seconds and does not support smaller time units, however, it is basically enough for a scheduled task ~
Scheduled tasks in Windows, crontab in Linux, and php call
The sum of all scheduled tasks created by each web user is all scheduled tasks of your system, but the scheduled time points are different. Therefore, your core point is to create a scheduled task.
You can create a scheduled task table to record the time points, actions, user IDs, and other information of each scheduled task, and then create a scheduled task to constantly refresh the table, if you find that a record is at a scheduled point, you can execute the corresponding action.
Specific ideas of some scheduled tasks can look at this article: http://segmentfault.com/a/1190000002955509
You can put the tasks to be executed into the database and write a background program to parse the database content or use the scheduled tasks of the system to start the interpreter for execution.
Discuz also has scheduled tasks. If you are interested, please take a look. However, discuz requires the user to trigger the speech to execute it.