Every time a user clicks a button, their "clicks" session key would be incremented by one. I think it would not be optimal to save that to the database per click since if the button can be clicked really fast.
How can I iterate through all the active sessions every x seconds and save them to the database? Would I create a cronjob for this?
@jlrdw When a user logs on, their session is initialized from their row in the database. I was using clicks as an example but something like "money" could also be used. When a user clicks a button, they fight a monster and gain "money". They can click the button as fast as they want and their money would increment based on the amount they clicked. I'm using Redis for session storage since writing to memory is much faster and more efficient than writing to a file for a database.
But the session should eventually be saved to the database, just not in real-time.
@drak you can get the final of this session and write to a table. I know you could add a button to click and have user data saved, but I don't know how you would do it automatically.
Even if you save a recent one it still may not be the very last one saved.
But yes I see what you are trying to do, see if having the user safe where they left off would work for you.