Scheduled tasks
Copy the code The code is as follows:
ignore_user_abort(); // The program is still executed when the user closes the browser
set_time_limit(0); // No limit on the 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 and stops start
echo str_repeat(' ', 4069); // PHP only checks the user connection status when outputting. The default value of output_buffering of 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
$query = "INSERT INTO `test`.`test_demo` (`title`, `content`) VALUES ('Scheduled Task', '" . date("Y-m-d H:i:s", time()) . "')";
mysql_query($query); // Use the write database verification program
sleep($interval);
} while ( true);
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. Some web servers' output_buffering The default value is 4096 characters. To ensure that flush() is effective, set it to 4069.
ob_flush();
flush();
// The user closes the browser to stop end
The above has introduced the Linux scheduled task PHP scheduled task to detect user connection status, including the content of Linux scheduled tasks. I hope it will be helpful to friends who are interested in PHP tutorials.