I have a code that runs in an infinity loops checking for events for me. and i control its stop using values from a database, but the problem is once i start the loop no other page will load or can be viewed until the loop is stopped.
set_time_limit(0)
$control = '';
while($control != 'stop'){
// keep checking for events functions goes here
$control = $search->query("SELECT status FROM mytable WHERE id = 1");
usleep(2000000);
}
Everything works perfectly but the problem is that other pages of my site does not load they will just be showing a loading spinning but no content is outputted, until i stop the while loop.
Is there a solution to this please?
secondly if i have an ajax call that posts to a file or url located in this web while the loop is still spinning can i get response or everything have to wait till i stop the infinity loop?
secondly if i choose to close or end the session will the loop still be running at the background while users go on accessing the page or pages without being affected by the loop?
It will only affect the task.php and yes when you close the session for this file the other files will be executed, because PHP is no longer waiting for the completition of task.php before it executes the next called file.