How to send Data form while loop : while executing?

I am trying to send Tasks to all connected users (say 1000).
I am to select random task froma a list of 100 tasks and send to user 1 by 1 on an interval of 15sec. As soon as any user completes 5 tasks he sends notification to validate. The while loop pauses here to validate the tasks, and resumes upon validation. While loop stops when 5 users have submitted currect task. All this to be done within the loop of 100 task.

I have created this task.php. And installed Ratchet websocket. But i am unabe to figure out how to use ratchet function to send and receive data from task.php. I am working on this link example of websocket connection.

Is there any alternative way to do it. I am doing SSR theory now.

set_time_limit(0);              // making maximum execution time unlimited
ob_implicit_flush(1);           // Send content immediately to the browser on every statement which produces output
ob_end_flush();                 // deletes the topmost output buffer and outputs all of its contents


$frstSen = 'The First Task is : ';
$taskCalled = array();
$taskTotal = 0;

//Selecting random task from 1 to 100
in_array(($task = mt_rand(1,100)), array($taskCalled));

//Send the task : To the connected User
echo $frstSen.' '.$task.'<br/><br/>';
sleep(15);

//Pushing the previous called task to taskCalled list
array_push($taskCalled, $task);


    while($taskTotal = count($taskCalled) <= 99){
        
        //Selecting random task from 1 to 100 excluding the previous called task 
        in_array(($task = mt_rand(1,100)), array($taskCalled));
        
        //Send the task : To the connected User
        echo 'The Next Task is : '.$task.'<br/><br/>';

        //Pushing the previous called task to taskCalled list
        array_push($taskCalled, $task);
        
        sleep(15);
        
        $taskTotal = count($taskCalled);
        
    }