PHP timed task Deferred implementation, PHP deferred _php tutorial

Source: Internet
Author: User
Tags sleep function

PHP Timer Task delay implementation implementation, PHP delay


Copy the Code code as follows:
/*
|---------------------------
| PHP timed Tasks
|@ Black-eyed poet
|---------------------------
*/
Ignore_user_abort (TRUE); Ignore script abort when client disconnects (Allow script to execute)

Set_time_limit (0); Set script maximum execution time, 0 unlimited

do{
$fp = fopen (' Auto.txt ', ' W ');

if ($FP)
{
$text = ' Hello \n\r ';

$count = 0;

for ($i =1; $i <10; $i + +)
{
if (! $c = fwrite ($fp, ' s. $i. ' line: '. $text))//Returns the number of characters written, false on failure
{
Echo ' first ' $i. ' Write Failed! ';
}

$count + = $i;
}
}

Fclose ($FP);

Sleep (60); Delay 60 seconds to execute

}while (TRUE);


How does PHP implement a timed script program?

If you want to use PHP files, you can barely do it.
There is a sleep function in PHP that uses sleep (time) where time is in seconds
First, create a PHP script
while (1) {
Yourcode
Sleep (3600*24);
}
?>
Yourcode here is what you want PHP script to execute the function, although can achieve this goal, but there are sacrifices, you have to be at 8 in the morning by the URL to access the script, that is, to execute the php file, and, this link can not be interrupted, to continue!! Or it will be ineffective.

PHP is a single-request execution, which is executed only if requested.

Whether PHP can automatically execute a code periodically

PHP is a need to trigger execution, there is no way to keep the execution of it, even if you use sleep, it still needs you to point it out first, it will always exist

The method is to use a scheduled task, that is, to plan the task, no matter Windows/*nix have a scheduled task, you can put PHP into the planning task, the command line to execute the PHP program

In fact, there is no possibility in the case of 0 access to PHP execution, because PHP itself is the server-side script interpretation tool, the server is of course someone to work just right, landlord in the opposite way, if you want to use PHP to perform desktop programs, there is no way, PHP official has this tool, But there are too many different ways to run PHP, so the controls are different, strictly speaking, just PHP syntax.

Additional additions to the questioner:
Ignore_user_abort (1);
Set_time_limit (0); The main study of these two

http://www.bkjia.com/PHPjc/890583.html www.bkjia.com true http://www.bkjia.com/PHPjc/890583.html techarticle PHP Timer Task delay implementation of the implementation, PHP deferred copy code is as follows:/* |---------------------------| PHP timed Tasks |@ black-eyed poet www.chenwei.ws |------------------------...

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