(1) The program starts once after the scheduled task is set up, and the program runs until the server restarts.
(2) If you run it repeatedly, it may not be the result you want, so you will start multiple same scheduled tasks
(3) If each page include this page, then start a number of permanently running programs consume unnecessary system resources,
It also affects the normal access of the page, if placed in front of the page will always be waiting for the return status (that is a dead loop)
<?php
Ignore_user_abort (TRUE); PHP scripts can continue to execute even if the client disconnects (such as turning off the browser).
Set_time_limit (0); Execution time is unlimited, php default execution time is 30 seconds, through Set_time_limit (0) can allow the program to execute indefinitely
$interval =60*5; Run every 5 minutes
$f = ' lock.txt ';
if (file_exists ($f)) {//To determine if a tag file exists, exits to prevent duplicate operation
Exit ();
}
do{
if (@get_file_contents ($f) = = ' Stop ') {//Set stop condition, stop when only write to Lock.txt stop
Break
}
@file_put_contents ($f, ' run ');//write a file repeatedly, flag already running scheduled task
.... Omit task code
Sleep ($interval);//program paused for 5 minutes
}while (TRUE);
@unlock ($f); Delete a tag file
?>
This is just one way of implementing code, and one way to do this is to use the PHP CLI pattern to implement the scheduled task.
Use Run->cmd as window
Run the Php.exe, then use the at, according to the requirements of the input can be
Different systems have different methods, and Linux is different. It didn't work out, but it's definitely OK.