How does javascript-php implement custom scheduled tasks?

Source: Internet
Author: User
Tags crontab syntax
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, UsecrontabTo 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.