开发者

Using PHP's __destruct method to log data when a connection is terminated

开发者 https://www.devze.com 2023-01-22 05:51 出处:网络
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

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 inter开发者_开发知识库cept the termination?)?

Thanks!


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消