php - Unlock table if browser is closed
If someone wants to edit an entry in a table, I put a column "Locked" to true. If the user closed the browser / tab, how can I do it best so that the value is written by "Locked" back to false?
Is that possible with ajax? This can be seen when the user closes the browser / tab, then that ajax event fired?
Or is there a better and more reliable method? I work with laravel 4 und MSSQL.
Answer
Solution:
This is very dangerous and highly unreliable, so if you need those rows unlocked, you better put a timeout on them too (a locked_at column), index the column and search for locked rows to unlock the timeouted ones. But...
You can hook on browser unload javascript event to help you with that:
Answer
Solution:
Tricky to do reliably, a couple of methods:
Use onbeforeunload as Antonio suggests, you could do an ajax request to release the lock?
Lock the record for x minutes on edit, then renew the lock via a polling ajax request just before the lock expires.