quiz - with session keep alive

quiz - with session keep alive

by Colin G -
Number of replies: 2

I was doing a 2 hour quiz recently in full screen the pop-up mode and my session timed out. When I clicked the next button after spending a very long time typing text and completing the task on the page I was left with only some debug info on the screen. This was a v2.6.1 so no autosave and I lost everything I had typed. Not good !!!!


This is hack will let you run a quiz with very long tasks while maintaining a short session time out. While the quiz attempt pages are open it keeps the users session alive - forever. Once the quiz has ended the session will timeout as normal.

This is for quiz mod v2.8.1 but easy to get working on older versions.

Copy the attached files to mod/quiz, flush your cache and the go to :

Site administration -> Activity modules -> Quiz -> quiz | keepalive

To activate session keep alive tick the box and save. You will see a security warning at the top of your quiz. Also a good idea to make sure autosave is turned on. The keep-alive is set for 4 mins so even the shortest 5min session timeout should not timeout. If anyone shows interest I may add a select box so the user can set the ping time. Longer is better.



Average of ratings: -
In reply to Colin G

Re: quiz - with session keep alive

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Just a warning to people who might use this: When the install instructions say "Copy the attached files to mod/quiz" - this will overwrite some of the standard Moodle files, which will cause problems the next time you try to upgrade.

Colin, I think you could implement your change as a self-contained plugin, if you wanted to make it easier or safer for people to use: https://docs.moodle.org/dev/Quiz_access_rules.

However, just turning on autosave is almost as good as this change for keeping the session alive, and it also autosaves.

In reply to Tim Hunt

Re: quiz - with session keep alive

by Colin G -
Yes the quiz I was doing was moodle 2.6 so there was no autosave. When my session timed out I was just left with a popup screen with debug info. The debug screen in a popup will be very confusing for many users.

If you turn autosave on does it keep the users session alive if they do not type anything ?