The use of Ignore_user_abort functions in PHP

Source: Internet
Author: User


The Ignore_user_abort function in PHP is that when the user turns off the terminal and the rear foot is still executing, it can be used to implement the scheduled task and the ongoing process, and the following example discusses the function and usage of the Ignore_user_abort () function.

Ignore_user_abort () can be implemented when the client is still able to execute PHP code after shutdown, you can keep the PHP process is always executing, you can achieve the so-called scheduled tasks and continuous process, only need to open the execution script, unless Apache and other servers restart or have script output, The PHP script will always be in the state of execution, at first glance very practical, but the price is a PHP execution script continuous process, expensive, but can achieve a lot of unexpected features.

It is described as whether setting up a disconnect from the client will terminate the execution of the script.

One, function prototype

int Ignore_user_abort ([bool setting])

Second, version compatible

PHP 3 >= 3.0.7, PHP 4, PHP 5

The basic usage and example of function

1, function base usage

Description: Invokes the Ignore_user_abort () function to declare that the execution of the script is not terminated even if the client disconnects.

2, combining the Set_time_limit () function to implement a cyclic script execution task

<?php

Ignore_user_abort ();

Set_time_limit (0);

$interval =60*15;

do{

The business performed

}while (TRUE);

?>
Description: Circular execution every 15 minutes

3, customizing the implementation of the file output and tracking the execution results of the ignore_user_abort () function

<?php

Gnore_user_abort (TRUE);

Set_time_limit (0);

$interval = 10;

$stop = 1;

do {

if ($stop = =) break;

File_put_contents (' viphper.php ', ' Current time: '. Time (). ' Stop: '. $stop);

$stop + +;

Sleep ($interval);

} while (true);

?>
Open the viphper.php file with the following contents:

Current time:1273735029 Stop:9

The idea is that even if the client terminates the script, it still executes every 10 seconds and prints out the current time and end point so that the Ignore_user_abort () function can be tested.

It is found that the Ignore_user_abort () function is very practical, realizes the planning task, completes the follow-up task, and the continuous process is very effective.

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.