Loading ...
Sorry, an error occurred while loading the content.

locking files

Expand Messages
  • Christian Gustavo Riva
    Hi. ... for($try=0; $try
    Message 1 of 1 , Jul 31, 2001
    • 0 Attachment
      Hi.

      I have the following code to lock a file:

      ---------
      for($try=0; $try<10; ++$try )
      {
      print "Try # $try..";
      if( open( FP, "+<file.txt" ) )
      {
      flock( FP, 2 );
      }
      }
      ---------

      In theory, if I lock the same file with other script, this script will count from 1 to 9 before
      stop to try open/lock the file.

      But not, the ' if( open... ) ' is TRUE always and the script start a 'stand-by' in the flock
      function, trying to lock and when the other script is closed, this finish. And only show me
      "Try # 1.." //

      The script that lock the file (for testing):

      ----
      open( FP, "+<file.txt" );
      flock( FP, 2 );
      sleep(20);
      close(FP);
      ----


      What am I doing wrong?

      Thanks

      Christian Gustavo Riva
      -> FonoMax® 2000 - Control Telefonico
      -> http://www.fonomax.com
      -> CGR Software - Programadores & Webmasters
      -> http://www.cgrsoftware.com
    Your message has been successfully submitted and would be delivered to recipients shortly.