There is a function in PHP that is useful. This was only gradually used in the recent development. The function of int ignore_user_abort ([bool setting]) is to indicate whether the server side continues to execute the following script after the remote client closes the connection.
The setting parameter is an optional parameter. If set to True, indicates that the script will not be affected if the user stops running the script (that is, the script continues to execute), and if set to false means that the script will stop running when the user stops running the script.
In the following example, after the user closes the browser, the script continues to execute on the server:
<?php
ignore_user_abort(); // 后台运行
set_time_limit(0); // 取消脚本运行时间的超时上限
do{
sleep(60); // 休眠1分钟
}while(true);
?>
This code will be executed forever unless the program is closed on the server.
-------------------------------------------------------------------------
<?php
ignore_user_abort(); // 后台运行
set_time_limit(0); // 取消脚本运行时间的超时上限
echo ‘start.‘;
while(!file_exists(‘close.txt‘)){
$fp = fopen(‘test.txt‘,‘a+‘);
fwrite($fp,date("Y-m-d H:i:s") . " 成功了!rn");
fclose($fp);
sleep(10);
}
echo ‘end.‘;
?>
From for notes (Wiz)
Keep PHP programs running in the background forever