--- "Ellis, Lantz C. CDR (C3F J32)" <[EMAIL PROTECTED]> wrote: > Any idea why I would be getting a 'does not support flock' statement > returned while running a cgi on the server? The cgi should open a file and > lock it while I add data and then release the lock when done. I am writing > a very simple shopping cart cgi and I need to store the order in the > client's shopping cart. I am using a text file in my account directory as a > flat file to store the info. > Thanks, > Lantz
Hi Lantz, I use an indirect method for locking files, which works fine on all platforms. I borrowed the method from a Matthew Wright script (tweaked a bit for my own taste in Perl style). The subroutines are as follows: sub lockFile { # Create a lock file for the file passed as a parameter. # If no parameter is passed, return a false value. $_ = shift or return 0; $_ = $_ . '.lock'; my $i; for ($i = 0; $i < $timeOut; $i++) { (-e $_) and sleep 1 and next; open LOCK, ">$_" or &outputError("Can't create lock file", $!); print LOCK '0'; close LOCK; last; } return 1; } sub unlockFile { $_ = shift; $_ = $_ . '.lock'; (-e $_) and unlink or &outputError("Can't delete the lockfile", $!); } If a file with the same name, appended with '.lock' exists, then the script checks every second up to the number of seconds specified in $timeOut ( I use 3 ) before allowing the file to be overwritten (this stops problems with writing to the file if a previous call was cancelled before deleting the lock file). Use them as follows: &lockFile( $file_name ); # Do stuff to $file_name here &unlockFile( $file_name ); Its a bit clunky, but it works on Mac, Unix and Windoze. HTH, Richard ===== Team Artonomy Drawing Business http://www.team-artonomy.com/ http://www.drawingbusiness.com/ The #1 Illustration studio on Google. Listed on Wow Web Designs, http://www.wowwebdesigns.com/ __________________________________________________ Do You Yahoo!? Everything you'll ever need on one web page from News and Sport to Email and Music Charts http://uk.my.yahoo.com