forum.vdsworld.com Forum Index forum.vdsworld.com
Visit VDSWORLD.com
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


File locking.

 
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> General Help
View previous topic :: View next topic  
Author Message
Bart
Valued Newbie


Joined: 24 Jun 2003
Posts: 41
Location: Netherlands

PostPosted: Thu Jun 26, 2003 10:23 am    Post subject: File locking. Reply with quote

Hi,

I'am looking for a way to lock a file when a script is adding something to it, i have a cgi script running on our server and that uses a file as a kind of queue.

I tried to create a file as indicator that the file is in use and deleted the file when it was done, but for some reason that doesn't work.

thanks
Back to top
View user's profile Send private message
FreezingFire
Admin Team


Joined: 23 Jun 2002
Posts: 3508

PostPosted: Thu Jun 26, 2003 11:20 am    Post subject: Reply with quote

Hi Bart. Welcome to VDSWORLD! Hi

What you are trying to do is not something that is currently a direct
command or function in VDS. You may either have to use VDS 5's
advanced API capabilities or have a custom DLL built for this. Smile

_________________
FreezingFire
VDSWORLD.com
Site Admin Team
Back to top
View user's profile Send private message Visit poster's website
nick
Contributor
Contributor


Joined: 15 Aug 2000
Posts: 50
Location: hamburg,nj

PostPosted: Thu Jun 26, 2003 1:32 pm    Post subject: Reply with quote

Hi Bart,

Try this:
Have your cgi retrieve the ip address of the client. Have the cgi read a lock file ie. 'lock.dat' to see if it has 0 bytes. If it has 0 bytes write the client ip address into lock.dat.

To be sure that this instance of the cgi actually was the first to write to lock.dat by checking the ip address written in lock.dat. If it is the same, this instance of the cgi has control and if so you can do other things. After you are done, clear the file lock.dat.

Use some loops in your program for lock checking & waiting.

I actually think I have used a much more elegant way of doing this using the binfile command. If you want I will search through my cgi's to see if I can find the routine.

You must also be careful to put in some error checking in case a wayward cgi bombs and doesn't unlock the file.

Let me know if I can help.

Nick

_________________
nick
Back to top
View user's profile Send private message
MarkTrubo
Contributor
Contributor


Joined: 27 May 2001
Posts: 148
Location: Long Island, NY

PostPosted: Thu Jun 26, 2003 10:26 pm    Post subject: Reply with quote

I use the write a file when in use technique all the time. When I delete it, I loop back one more time just to make sure it is gone. Also, if I detect I file lock is on, I start a timer countdown for a bit longer than a lock should exist and then delete it. This helps ensure that there is never a problem.
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger
Bart
Valued Newbie


Joined: 24 Jun 2003
Posts: 41
Location: Netherlands

PostPosted: Wed Jul 09, 2003 10:38 am    Post subject: Reply with quote

It works, i use a lock.dat file but write a "1" if locked and a "0" if not and let the script wait until it's "0" and it seems to work.

Thanks
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> General Help All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum

Twitter@vdsworld       RSS

Powered by phpBB © 2001, 2005 phpBB Group