Scheduled tasks
Copy codeThe Code is as follows:
Ignore_user_abort (); // The user closes the browser and continues to execute
Set_time_limit (0); // no restriction on the running time
$ Interval = 3; // The interval between program loops in seconds
$ Link = mysql_connect ('localhost', 'username', 'passwd ');
Mysql_select_db ('test ');
Mysql_query ("set names 'utf8 '");
Do {
// Close the browser and stop start
Echo str_repeat ('', 4069); // php checks the user connection status only during output. the default value of output_buffering for some web servers is 4096 characters. to ensure that flush () is valid, set it to 4069.
Ob_flush ();
Flush ();
// The user closes the browser and stops the 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 );
If no php is output, the user connection status cannot be detected. Even if you close the browser program, it will still run until the apache service is stopped or restarted.
Copy codeThe Code is as follows:
// Close the browser and stop start
Echo str_repeat ('', 4069); // php checks the user connection status only during output. the default value of output_buffering for some web servers is 4096 characters. to ensure that flush () is valid, set it to 4069.
Ob_flush ();
Flush ();
// The user closes the browser and stops the end