I have this code that may take long periods of time to finish running (long loops). My progress is being saved when the loop finishes, but I might get impatient or my browser accidently close, etc. So I need a way to remember where I left off in case I lose the connection. Is there some way to detect when the client is disconnected or hits the stop button?