| View previous topic :: View next topic |
| Author |
Message |
Bart Valued Newbie
Joined: 24 Jun 2003 Posts: 41 Location: Netherlands
|
Posted: Thu Jun 26, 2003 10:23 am Post subject: File locking. |
|
|
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 |
|
 |
FreezingFire Admin Team

Joined: 23 Jun 2002 Posts: 3508
|
Posted: Thu Jun 26, 2003 11:20 am Post subject: |
|
|
Hi Bart. Welcome to VDSWORLD!
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.  _________________ FreezingFire
VDSWORLD.com
Site Admin Team |
|
| Back to top |
|
 |
nick Contributor

Joined: 15 Aug 2000 Posts: 50 Location: hamburg,nj
|
Posted: Thu Jun 26, 2003 1:32 pm Post subject: |
|
|
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 |
|
 |
MarkTrubo Contributor


Joined: 27 May 2001 Posts: 148 Location: Long Island, NY
|
Posted: Thu Jun 26, 2003 10:26 pm Post subject: |
|
|
| 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 |
|
 |
Bart Valued Newbie
Joined: 24 Jun 2003 Posts: 41 Location: Netherlands
|
Posted: Wed Jul 09, 2003 10:38 am Post subject: |
|
|
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 |
|
 |
|