Question

Currently I am working on a system in PHP (for syncing data between webservices) (using the Lithium framework) which makes multiple requests to different webservices through curl.

For every response in a request (could be quite some few, lets say 100). However when the client disconnects (e.g. presses stop in the browser) the script continues to running (the log lines keep coming in the log file) 'long' after the client is disconnected.

From what I've read PHP only detects client disconnection when it tries to send output to the browser. So now I am flushing some data after every requests (and every line to the log file) to the browser. But the PHP script continues to run.

I now have the following code after each log call, however this does not seem to work.

//Die on no connection
ignore_user_abort(false);
echo chr(0); flush(); ob_flush();
if(connection_aborted())
{
    die();
}

The script just keeps running, it there anything I can do to make sure the script stops after the client (or at least soon after) disconnects?

edit: Why do I always find the solution after posting a question. added 'ob_flush' and that seems to work. Thanks anyways for anyone who has looked into this.

Was it helpful?

Solution

try using ob_flush() instead of flush(), that will flush the output buffer..

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top