> -----Original Message----- > From: Jon Block [mailto:[EMAIL PROTECTED] > Sent: Thursday, March 27, 2003 4:09 PM > To: CF-Talk > Subject: File locking from CF5? > > > Lets say I have two CF5 enabled web servers with a single > directory they both can access. Server A occasionally will > write "hello.txt" with a CFFILE tag to the shared directory. > Server B will periodically read the "hello.txt" from the > shared directory when serving out web pages. > > The problem is that sometimes I get a CF exception on server > A becuase hello.txt can't be written while server B is > reading from it. > > I have read up on CFLOCK but it seems thats only good for > isolating chunks of code in a single server. In this case I > have a cluster and cflock won't protect against threads > trying to access hello.txt on a different machine.
True. You pretty much have to have to build some kind of indicator yourself that does the same task as locking. There are many possibilities: 1) You might set a flag in a DB. Before a server accesses the file it checks a cell that contains a "working" bit. If the bit is clear it can set the bit and use the file (setting it to clear when it's done), otherwise it waits. 2) You could rename the file while it's being worked with. The other server would do a FileExists() - if it sees the file it can assume it's free, change it's name work with it then change it's name back. 3) You could implement a "lock file" - the server would create a special file in same directory when it was working with the file and delete it when it was done. The other server would check for the existence of the lock file before accessing it. In effect you're creating a traffic cop with two states: "all clear" and "in use". For all of these you would probably also have to provide some failsafes (what if a sever goes down with the file locked and so on). Jim Davis ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| Archives: http://www.houseoffusion.com/cf_lists/index.cfm?forumid=4 Subscription: http://www.houseoffusion.com/cf_lists/index.cfm?method=subscribe&forumid=4 FAQ: http://www.thenetprofits.co.uk/coldfusion/faq Structure your ColdFusion code with Fusebox. Get the official book at http://www.fusionauthority.com/bkinfo.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4