PHP Scheduled task detects user connection Status _php tutorial

Source: Internet
Author: User
Scheduled Tasks
Copy CodeThe code is as follows:
Ignore_user_abort (); User Close Browser program still executes
Set_time_limit (0); No limit on program run time
$interval = 3; Program Cycle time interval 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 only checks the user connection status when it is output. Some Web servers have a output_buffering default value of 4096 characters. To ensure that 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); Use Write Database Validator
Sleep ($interval);
} while (true);

If there is no output PHP is unable to detect the user connection status. Even if you close the browser the program will still run until the Apache service stops or restarts.
Copy CodeThe code is as follows:
User closes browser stop start
Echo str_repeat (', 4069); PHP only checks the user connection status when it is output. Some Web servers have a output_buffering default value of 4096 characters. To ensure that flush () is valid, set to 4069.
Ob_flush ();
Flush ();
User closes browser stop end

http://www.bkjia.com/PHPjc/325193.html www.bkjia.com true http://www.bkjia.com/PHPjc/325193.html techarticle The Plan task copy code code is as follows: Ignore_user_abort ();//user Close browser program still executes set_time_limit (0);//No Limit program run time $interval = 3;//program Loop ...

  • Related Article

    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.