[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: A script problem



Brian Loss schrieb:
> 
> Hello Pi3-users!
> I downloaded a free script from http://www.dcscripts.com called
> DCProtect. I thought it would work, because it said it was compatible
> with unix and nt. I read the instructions, but when I ran it, it had
> problems.
> I ran it on a DOS prompt, it said something like "flock () is not
> compatible with WIN95".
> Could someone download it, and see what the problem is?
> Also, look at the sample.cgi file completely, It has varibles to be
> corrected.
> If "flock()" will not work with win95 could it be disabled or altered to
> work?
> 
> Also, I heard that when this script was introduced, you had to pay 30
> u.s. dollars, expensive for a script?
> 
> Thanks a lot for helping,
> Brian
> 
> ______________________________________________________
> Get Your Private, Free Email at http://www.hotmail.com

Hi Brian,

in fact the file locking by flock() isn't working with the windows
version of perl. I use the following workaround for this:

$locktimeout = 30;

sub Lock {
   my $result = 0;
   my $lockfilename = shift(@_);
   $lockfilename =~ s/[.]+[a-z]*/.lck/gi;
   $lockfilename =~ tr/[A-Z]/[a-z]/;
   my $to = time + $locktimeout;
   my $ti = time;
   while ((-e $lockfilename) && ($ti <= $to)) {
      $ti = time;
   };
   # lockfile timeout ?
   if ($ti <= $to) {
      open(LOCKFILE, "+>$lockfilename");
      close(LOCKFILE);
      $result = 1;
   };
   return $result;
};


sub Unlock {
   my $result = 0;
   my $lockfilename = shift(@_);
   if (-e $lockfilename) { 
      $lockfilename =~ s/[.]+[a-z]*/.lck/gi;
      $lockfilename =~ tr/[A-Z]/[a-z]/;
      unlink($lockfilename);
      $result = 1;
   };
   return $result;
};

I think you cannot go without file locking mechanisms if the script
is used on a web server.
-- 
with regards
Holger

---------------------------------------------------------
Holger 'Zimpel' Zimmermann    Contact me:
---------------------------------------------------------
Wendishain                    tel./fax company: on demand
Germany                       tel./fax private: on demand
---------------------------------------------------------
homepage: http://home.t-online.de/home/zimpel/
web server: surf to it from my homepage (online every
            Sunday 20:00-24:00 GMT, start shifted again)
e-Mail:     zimpel@t-online.de
--------------------------------------------------------