hi there
i have a problem with online exam time that will be manage during the exam by ajax.
in each ajax request, i will send the remain time and store it in a db table.
the problem is if i use short intervala for exam send request every one second, it’s so heavy for the server and if use longer intervals like 10 seconds gap between each ajax request, use can hit refresh and dont let time to change
When exam is started, store current server’s timestamp as start_time
Mark exam as started by setting is_started flag to true
Pass current server’s timestamp (current_time) and start_time to client while rendering exam page
Client:
Calculate remaining time using current_time and start_time received from server (remaining_time = current_time - start_time). Don’t use client’s own current time as it can be in different timezone.
Show countdown timer;
Don’t send any time requests to server at all, they’re useless;
If time is out, redirect client somewhere (or do whatever you want)
If user refreshes the page nothing bad will happen, because server see that exam is already in progress (is_started == true) and just sends new current_time and old start_time to client. So client calculates remaining time again and get the same amount as before refreshing.
When user ends exam (submits form):
Server:
Check is_started == true
Check time() - start_time is less than allowed time limit
If any of checks above is not true, show error and don’t accept user answers
Save user answers
Set is_started flag to false
Those two checks will not allow user to block countdown timer in his browser, because actual time counting is handled by server and client shows timer only for user’s convenience.
thanks a lot
so how handle those kind of users that faced with problem during the exam and want to continue the exam after their problems, the problems can be unexpectedly restart the computer, or internet connection fail etc etc
It’s up to you how to handle such situations
In general you may have some “restart” action that will clear is_started flag and shuffle questions in the quiz or something like that.