0

I currently have a class that sets the current time when an object has been created from it. After the object has been created, I have code that goes into an infinite loop that sleeps once every second. All this is triggered by a user going to a web page (so at this point, your browser would just be waiting). Now, if the user stops their browser, the connection terminates. I'm trying to get the classes' __destruct method to call when this happens so that I can track the time between loading of the script and termination by the user.

It doesn't seem to be working though. I'm assuming it's because the script isn't terminated properly, but if that's so, how can I call that code (or intercept the termination?)?

Thanks!

Jack Slingerland
  • 2,651
  • 5
  • 34
  • 56
  • *(related)* [Does php execution stop after a user leaves the page?](http://stackoverflow.com/questions/1280291/does-php-execution-stop-after-a-user-leaves-the-page) – Gordon Oct 28 '10 at 22:30

2 Answers2

2

php does not know and cannot find out by itself whether the user's browser is still running or not.

middus
  • 9,103
  • 1
  • 31
  • 33
0

You will need to keep polling the browser for a connection. If you keep scripts alive using sleep, they keep running regardless of what the user does.

I can't offer a solution though, since I have never implemented long polling.

degenerate
  • 1,224
  • 1
  • 14
  • 35
  • Unfortunately it looks like that requires javascript to work. I need it to work without it (unless I mis-understand your intentions) – Jack Slingerland Oct 28 '10 at 18:27
  • Yeah this needs javascript -- without JS I don't see how you are going to interact with the browser after loading the page. As middus mentions, you basically can't. – degenerate Oct 28 '10 at 18:57