Php function (ignore_user_abort) that can be executed after the browser is closed)

Source: Internet
Author: User
If you want to close the browser, the program will continue running in the background. in this case, you need to use the ignore_user_abort () function to avoid having to talk about it. go directly to the code:

The code is as follows:


Ignore_user_abort (true); // Sets whether the script execution is interrupted when the client is disconnected.
Set_time_limit (0 );
$ File = '/tmp/ignore_user.txt ';
If (! File_exists ($ file )){
File_put_contents ($ file );
}
If (! $ Handle = fopen ($ file, 'A + B ')){
Echo "not open file:". $ file;
Exit;
}
$ I = 0;
While ($ I <100 ){
$ Time = date ("Y-m-d H: I: s", time ());
Echo $ time. "\ n ";
If (fwrite ($ handle, $ time. "\ n") === false ){
Echo "not write file:". $ file;
Exit;
}
Echo "write file time:". $ time. "\ n ";
$ I ++;
Sleep (2 );
}
Fclose ($ handle );

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.