This connection_aborted method in PHP doesn't work the way you think. It will tell you if the client is disconnected, but only if the buffer has been flushed, i.e. Some kind of response is sent from the server back to the client. PHP versions will not work, as you wrote, if above. You will need to add a call to something like flush in your loop so that the server tries to send data.
HTTP is a stateless protocol. It is designed so that the client or server does not depend on each other. As a result, the state is either known only when the connection was created, and this only happens when some data is sent one way or another.
It’s best to do what @MattH suggested and do it through a bit of AJAX, and if you want to integrate something like Node.js to make the client “check-ins” during processing. However, how to correctly establish this, I am not in my field of knowledge.
source share