Chrome与PHP,无限循环

I have a PHP app running inside a Docker container. While testing websockets I am using an infinite loop to wait for response from the server. Endpoint is an AJAX call triggered on click, ultimately hitting this method:

public function searchMessages()
{
    while (true) {
        sleep(2);

        $message = $this->client->getMessages();
        if($message){
            $this->_save(...);
        }
    }
}

From that point on, endpoint opens and never ends. I presumed that reloading the page would get me back to my home page (where I can click the button to trigger AJAX again), but that is not the case. If I try to close/reload, Chrome is just stuck on infinite load and never shows the page again unless I kill the container.

How can I keep on testing without shutting down my container over and over again?