Synchronizing Timer: Client Start to Database Logging

I want to build a timer that begins on click and stops on another click, logging elapsed time. Given inactive tabs reduce timer accuracy, how can PHP verify timing?

hey haz, i think using a clientside js timer that sends ajax updates to php might work. i wonder if this shift in logic could overcome tab inactivity issues? anyone else try something similar?

hey haz, try sending server timestamps on each click. that way, even if the tab is inactive, php does the calc on the exact start and stop times. network delay might add a smidge, but it beats relying solely on js.

An effective solution involves minimally relying on client-side timers for critical logging and delegating the actual time calculations to the server. In my experience, triggering an AJAX request upon the initial click that passes a timestamp to PHP combined with recording the stop time using another server request delivers much better accuracy. This method ensures the server performs all duration calculations, reducing impact from client-side inaccuracies due to inactive or backgrounded tabs. It is important to handle potential device latencies carefully, though the overall approach remains robust across varied conditions.