Long Polling causes problems when user exits page
-
11-10-2019 - |
Question
My Long Polling system runs using PHP and jQuery but I have encountered a problem when developing it.
When the user exits the page it seems to like 'jam' and the AJAX request seems to remain and won't exit.
Anyone know how to prevent / overcome this?
Solution
Is this server side or client side?
Client side, you can abort() the outstanding XMLHttpRequest.
Server side, you can introduce a timeout, and raise an exception or signal when it expires. Look into the pcntl_alarm() call, which raises the SIGALRM signal (check pcntl_signal() for how to catch this).
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow