Home > Backend Development > PHP Tutorial > Linux scheduled task php scheduled task detects user connection status

Linux scheduled task php scheduled task detects user connection status

WBOY
Release: 2016-07-29 08:48:20
Original
923 people have browsed it

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);


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. 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.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template