How does think implement php scheduled task execution and the time is configurable

Source: Internet
Author: User
You need to make a php task for scheduled execution. Three methods are found: 1 is the Windows scheduled task, 2 is the linux shell, 3 is the php sleep method. I can't even think about it. I can get custom time intervals from the database to execute code at regular intervals. You need to make a php task for regular execution. Three methods are found: 1 is the Windows scheduled task, 2 is the linux shell, 3 is the php sleep method. I can't even think about it. I can get custom time intervals from the database to execute code at regular intervals. Tutorial

Reply content:

You need to make a php task for scheduled execution. Three methods are found: 1 is the Windows scheduled task, 2 is the linux shell, 3 is the php sleep method. I can't even think about it. I can get custom time intervals from the database to execute code at regular intervals. Tutorial

Crontab

Write a PHP file, write a shell script, set crontab to regularly execute the script, and execute the PHP file in the shell script.

One idea is to write only one crontab task and run the script cron. php once every minute.

Then all your logic is written in cron. php. In cron. php, you can determine whether to execute a task or exit directly.

Http://laravel-china.org/docs/5.0/artisan#scheduling-artisan-commands

Throw the time to be executed to the redis queue and other queues. Then, php while reads the queue all the time, executes the queue at the time, and continues to throw the queue until the time is reached.

It can be used in combination.
Answer: in linux
Use crontab to execute a scheduled task and regularly execute a PHP file. The file content can be executed according to the time.
For example:

Punlic function doAction () {$ actionTime = 'select .... '// obtain the time from the database if ($ actionTime> time () {// judge the current time and the specified time to execute the operation ...} else {....}}

The details can be optimized, such as cache operation results, reducing the number of database queries and reducing overhead.

How about js? Is there a trigger? It's all through the system's scheduled tasks. Otherwise, you can write an endless loop, so that this program can be executed all the time. By judging the timestamp, your machine will be dragged down, cool, in linux, website development is a comprehensive application. php alone cannot accomplish everything. web developers must expand js and linux knowledge.

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.