Maybe we can use the PHP function `connection_aborted()` to check if user close the page,if page is close, we can break the loop ?