Scheduled task
Copy code The code is as follows:
ignore_user_abort(); // The user closes the browser and the program is still executed
set_time_limit(0); // No limit on program running time
$interval = 3; // Program loop interval seconds
$link = mysql_connect('localhost', 'username', 'paswd') ;
mysql_select_db('test');
mysql_query("SET NAMES 'utf8'");
do {
// The user closes the browser to stop start
echo str_repeat( ' ', 4069); // PHP only checks the user connection status when outputting. The default value of output_buffering for some web servers is 4096 characters. To ensure that flush() is effective, set it to 4069.
ob_flush();
flush();
// The user closes the browser and stops end
$query = "INSERT INTO `test`.`test_demo` (`title`, `content`) VALUES ('Scheduled Task' , '" . date("Y-m-d H:i:s", time()) . "')";
mysql_query($query); // Use write database verification program
sleep($interval) ;
} while (true);
If there is no output, php cannot detect the user connection status. Even if you close the browser program, it will still run until the apache service is stopped or restarted.
Copy code The code is as follows:
// The user closes the browser to stop start
echo str_repeat(' ', 4069 ); // php only checks the user connection status when outputting. The default value of output_buffering for some web servers is 4096 characters. To ensure that flush() is effective, set it to 4069.
ob_flush();
flush() ;
// The user closes the browser to stop end
http://www.bkjia.com/PHPjc/325193.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/325193.htmlTechArticleScheduled task copy code code is as follows: ignore_user_abort(); // The user closes the browser program and still executes set_time_limit(0) ; // No limit on program running time $interval = 3; // Program loop...