The ignore_user_abort () function is required to run the program in the background after the browser is closed.
The ignore_user_abort () function is required to run the program in the background after the browser is closed.
If you do not need to mention 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 );