Scenario:
What is the best way to do this?
On *nix:
exec('/path/to/executable > /dev/null 2>&1 &');
On Windows:
$WshShell = new COM('WScript.Shell');
$oExec = $WshShell->Run('C:\path\to\executable.exe', 0, false);
Both of these will spawn a new process that will run a-synchronously, completely disconnected from the parent. As long as your host allows you to do it.
You can google by key: php continue processing after closing connection.
The following links that relate to your problem, are:
You can use belong command to continue executing without user aborting
ignore_user_abort(true);
set_time_limit(0);
You use fastcgi_finish_request to alert client to stop the response output. And your scripts will continue to be executed.
An example:
// redirecting...
ignore_user_abort(true);
set_time_limit(0);
header("Location: ".$redirectUrl, true);
header("Connection: close", true);
header("Content-Length: 0", true);
ob_end_flush();
flush();
fastcgi_finish_request(); // important when using php-fpm!
sleep (5); // User won't feel this sleep because he'll already be away
// do some work after user has been redirected
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With