Infinite loop

I'm using Nginx as my web server. And it seems like the connection_aborted() function in sse_loop() of /api/helper.php doesn't work. It kept sending request as what the following picture shows after I closed the page in my browser due to the infinite while loop that contains it. This is /var/log/nginx/access.log: /var/log/nginx/access.log Currently, I ain't get any better solution than just automatically break the while loop after a certain amount of time.