Php scheduled task detection user connection status
Source: Internet
Author: User
Php scheduled task detection user connection status scheduled task
The 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
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.
The 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
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.