Multi user environment.

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Hello, I am developing a CMS and I would like to be able when a user is  
editing a page to inform any other user that the page is being edited by  
User X . Ofcourse that's not so difficult if you set a flag in the database  
for example that the current document is being edited, and remove the flag  
when the user saves the document and exits.

BUT what happens if user exits the editing page without folowing any link or  
submit button that I can control. What happens if his computer  
restarts/crashes or he kills the browser.

Database will have the document flaged as being edited by User X.

Do you know any good way of avoiding that problem or if you don't already  
know, can you think of something similar ?

Thanks Angelos.  

Re: Multi user environment.

Hi there Angelos,

You could create a javascript function that sends a signal to the
server when the editing page unloads. onUnload is a standard javascript
event supported by every browser (that has javascript support switched

Alternatively, if your server supports cron jobs, you could create a
program that runs in the background and checks the flag's status every
30 minutes or so. If the status hasn't changed for, say more than 30
minutes, you may assume the user has left the page and the flag should
be reset. This acts as a sort of timeout function.

Kind of a cool problem you are dealing with!

Regards, Maarten

Re: Multi user environment.

Maarten said the following on 08/11/2005 14:45:
Quoted text here. Click to load it

Unfortunately, this isn't failsafe by any stretch of the imagination;  
e.g. Javascript disabled, browser crashes, computer crashes, internet  
connection lost. I also believe that onUnload is fired if the user  
refreshes the page in their browser.

Even if these events only occur once in a day, your database is  
immediately unsynchronised, and will probably require manual  
intervention to sort it out.

Quoted text here. Click to load it

IMO, a cron job is unnecessary. If you store the "check-out" time of  
each article in the DB, then you can perform time-out checks can be  
performed every time a user requests a PHP page.

e.g. perform the following query at the top of every script:

    UPDATE articles
        SET isCheckedOut = 0
        WHERE (checkOutTime + X) < NOW()

In practice, you can probably find ways to avoid doing this amount of  
processing in every script, but you get the general idea...


Re: Multi user environment.

Quoted text here. Click to load it

I had the same problem, too. I did the cleaning up process through a
php page that was called less frequently, but not as much to keep the
flag On for half a day. By estimate,(not reliable, but the best I could
think of at that time) this page would be run every half or one hour.
After doing all the work the page was supposed to do, it called this
little cleanup() function, something which it was not _supposed_ to do,
but did a good job of.

My question is, is there no daemon creating mechanism in PHP?

Any clues, googling gave this one useful result:
but not exactly what I am looking for -

making any script or function run continuously.

The only things we have continuously present is the superglobals
$_GET,$_POST,$_SERVER etc.- no code.

Joseph S.

Re: Multi user environment.

Thanks For all your Answers !!!
It is a hard one ... I haven't found any mechanism to get rid of the  
FLAG but I think is one of those things that require the human  
intervention. :)


Re: Multi user environment.

Angelos wrote:
Quoted text here. Click to load it

What was wrong with the timestamp (i.e. storing the check-out time in
the DB, and automatically resetting documents that have been checked
out longer than time X) suggestion?


Re: Multi user environment.

Personally, I'd go with checking the timestamp when you want to check
the page out, but you could add in an ajax routine to update the time
stamp every 60 seconds while it is being edited. It could also pick up
and warn the person editing that someone else was trying to get to it.


Site Timeline