I'm currently running a loop in my PHP script to check if the user connection has been aborted (connection_aborted() does not work on ajax calls):
connection_check.php
:
<?php
ignore_user_abort(true);
for ($i = 0; $i < 1000; $i++) {
echo "<br>";
flush();
ob_flush();
if (connection_aborted()) {
echo "nocon";
exit;
} else {
// Everything is fine
}
sleep(3);
}
?>
However, I also need to run the rest of my PHP code while this loop is running in the "background" so that when the connection is aborted, the script dies, but if it is not, the script should continue to run. I need to do this because I'm calling this PHP file with an ajax call.
This is what I've tried, however, it isn't working (the script continues to run and does not die, connection_check.php
does not echo "nocon"):
file.php
<?php
$child = fopen('http://ipaddress/core/connection_check.php', 'r');
/***
* ALL PHP CODE HERE THAT SHOULD START RUNNING RIGHT AWAY WHILE CONNECTION_CHECK.PHP RUNS IN THE BACKGROUND
***/
$response = stream_get_contents($child);
if($response == "nocon") {
die();
}
?>
Any help? If anybody has an alternative, that would be appreciated as well. I've been tring to work on this for over a day, and no luck yet.