dl__
dl__

Reputation: 4610

Detecting browser shutdown in PHP

I know I can use connection_aborted() to explicitly check if the browser closed but then I have to check at discrete points and the browser may close in between my checks.

Is there an exception or something I can catch (I couldn't find one). I have some processes that may run long and if someone shuts down the browser, and thus aborts the process, I just want to log that such a thing happened.

Upvotes: 1

Views: 239

Answers (2)

cwallenpoole
cwallenpoole

Reputation: 82058

No. The browser does not have to tell the server that it is about to close a connection. You can try to simulate it with JavaScript pings, but even that is more than error-prone.

Upvotes: 1

mystery
mystery

Reputation: 19523

You can't tell if the browser shut down, as HTTP is a stateless protocol. Checking if the connection terminated tells you (usually) if the user lost connection or aborted during page loading. You can only check for closing the browser client-side using JavaScript.

Upvotes: 1

Related Questions