PHP Scheduled task detects user connection status _php tips

Source: Internet
Author: User
Planning tasks
Copy Code code as follows:

Ignore_user_abort (); User closes browser program still executes
Set_time_limit (0); Do not restrict program run time
$interval = 3; Program Cycle interval Time seconds

$link = mysql_connect (' localhost ', ' username ', ' paswd ');
mysql_select_db (' Test ');
mysql_query ("SET NAMES ' UTF8 '");

do {
User closes browser stop start
Echo str_repeat (', 4069); PHP checks the user connection status only on output. Some Web server output_buffering default values are 4096 characters. To ensure flush () is valid, set to 4069.
Ob_flush ();
Flush ();
User closes browser stop end

$query = "INSERT into ' test '. ' Test_demo ' (' title ', ' content ') VALUES (' Scheduled task ', '". Date ("Y-m-d h:i:s", Time ()). "')";
mysql_query ($query); Using the Write Database validator
Sleep ($interval);
} while (true);

If PHP is not output, the user connection status cannot be detected. Even closing the browser program runs until the Apache service is stopped or restarted.
Copy Code code as follows:

User closes browser stop start
Echo str_repeat (', 4069); PHP checks the user connection status only on output. Some Web server output_buffering default values are 4096 characters. To ensure flush () is valid, set to 4069.
Ob_flush ();
Flush ();
User closes browser stop end

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.