'Is there a way to sleep a specific function instead of all script execution in php?

I'm trying to make a php function loop every 5 seconds, but can't have it pause all script execution since other parts of the script need to get stuff done.

    public function status($discord, $status = statusarray, $infinite = true) {
        shuffle($status);
        $activity = $discord->factory(\Discord\Parts\User\Activity::class, [
            'name' => $status[1][0],
            'type' => $status[1][1]
        ]);
        echo "Changed status to \"".$status[1][0]."\" Type of status:".$status[1][1].PHP_EOL;
        $discord->updatePresence($activity);
        if($infinite) {
            sleep(5);
            $this->status($discord, $status, $infinite);
        }
    }

This is my code, which chooses a random status every 5 seconds for a discord bot.
That's what $status is, and why it's shuffled.
I have this part of my code on another file for functions specifically on a class.
But, the if($infinite) part of the script pauses script execution. Which is the problem.
I've been trying all day to find a way for it to not pause script execution, but haven't found anything helpful, so i'm here once more, waiting for Stack Overflow to do it's thing and give me something i would have never been able to think of.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source