It's a long running script and needs to be running even when user closed the browser.
<?php
ignore_user_abort(true); //run even when user disconnected.
set_time_limit(0); //run forever if that's what you need :)
$report = "";
while(1){
// do stuff and touch $report
}
//And the line below doesn't work when user disconnected.
file_put_contents("./offline.txt", $report, FILE_APPEND | LOCK_EX);
?>
I have tried register_shutdown_function() but it doesn't seem to work.
Is there any quick fix or other alternative solution which handles the task?