I am building a site that will track user events with time constraints. Each user will be able to create events, and after the expiration date the server will need to take some actions based on the result of the event. The specific component I'm struggling with is time: think like the hours of an eBay auction - it expires at a specific time, obviously works on the server side and takes some action when the time runs out. Searches for a "server-side timer", unfortunately, it simply returns the results for a timer that receives time from the server, not from the client. :(
The most obvious solution is to run the script on the server, some program that will monitor all the clocks and take action when any of them have expired. Tragically, I will use free web hosting and sincerely doubt that I will find anyone who will let me run arbitrary things on my servers.
The solutions I reviewed:
Basic conceptual option 1: convince each user browser to start the necessary timers (trivial javascript), and when the timers expire, take the necessary actions. The problem with this approach is obvious: there can be hundreds, if not thousands, of expiring timers (they usually expire in clusters), and the worst case is that every possible user can view their timer. That server overload is expected at the most dangerous moment.
The main version of concept 2: there is one really trusted browser, say, a user registered on the website as "cron", which can start all timers at once. The action will take place in this javascript browser and will work perfectly if this browser never crashes, this machine never lost, and that the internet connection never dropped.
As you can see, I feel like I'm barking a false forest on this issue. Some other ideas that introduced themselves:
AJAX: I don’t see anything here that will do what I need. All this works with a browser, nothing like a server process that can work independently of a user browser. PHP: executed neatly on the server, but only in response to client requests. I don’t see any clean way to turn PHP into a process and start a timer that is not dependent on a custom browser. JS: the same problems as PHP, but easier to read .;) Ruby: There may be several multi-threads with Ruby, but I don’t understand this. It would be possible for each user browser to check whether the timer process for their event was started, and to spawn a new ruby server process on the server side, if this is not so?I am widely open to ideas - I started playing with concepts in JS and PHP, but I am not attached to any language in particular. The only limitation, in fact, is that I will not be the owner of the server on which I launch the site, so I can’t just start the neat little local process that does what I need. :(
Any suggestions? Thanks in advance,
Dan