Jump to content

PHP on unload


The Little Guy

Recommended Posts

What I am doing, is when a user goes to edit a file, the file gets locked to everyone else. When the file is done being edited, I want the file the be unlocked (by file I mean a cell in the database).

 

so if someone closes the page, I would like to unlock the file.

Link to comment
https://forums.phpfreaks.com/topic/115331-php-on-unload/#findComment-592945
Share on other sites

I think the best way would be via an AJAX heartbeat of sorts, where you will have a field on your database that shows what time it was 'checked out' and use AJAX to post back an update every so often, say 30 seconds.  When a user wants to open that file you will check to see if it has been more then 30 seconds since the 'checked out time' and if it has then the user is no longer editing the file.  Then when a user saves or cancels (but remains on the page) you will set the 'checked out time' to somthing like Linux Epoch (Jun 1st 1970) for example.

Here are an example: http://ajaxpatterns.org/Heartbeat

and a quick google for 'ajax heartbeat' returns

Link to comment
https://forums.phpfreaks.com/topic/115331-php-on-unload/#findComment-592952
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.