Imagine a turn-based 1 vs 1 browsergame.
I need to be able to detect when a user goes offline (exits the browser, shuts down the PC, disables JS), and perform some actions.
Since I already have to costantly poll the server with AJAX to get the data, I thought that maybe I could add a line to my code that records in the DB the current time, and check if the other user's last connection time is < than (current time - 3 seconds), in wich case I consider him offline and declare the first user winner (add exp and money etc.)
But, what if one user exits, and after 1 second, the other does the same? Then he does not have time to detect the other user's logout. Nobody gets the Exp, but, most important, the entry in the "active fights" database does not get deleted.
Any ideas?
EDIT: Cron-jobs are a no-go, since Altervista, my PHP hosting website, requires me to pay for them and I can execute them every 60 minutes at best, while I would need them to run max every 5 seconds or so