While a page is still loading, you can test to see if the client is still there by printing something to the socket and seeing if you get SIGPIPE or similar. Once the page has stopped loading, there's no way to tell except to use a timeout and make some educated guesses.