| 
	
 | 
 Posted by Oli Filth on 06/14/23 11:31 
Maarten said the following on 08/11/2005 14:45: 
> 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 
> on). 
 
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. 
 
 
> 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. 
 
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... 
 
 
--  
Oli
 
[Back to original message] 
 |