|  | Posted by sven.holcombe on 09/21/06 02:44 
Hi there,
 I'm trying to just prevent multiple instances of a script running.
 
 I would have thought that the following code would do this for me.
 
 <php
 $fp = fopen("foo.txt", "w");
 flock($fp, LOCK_EX + LOCK_NB) or die ("Could not get lock!\n");
 echo "Got lock!\n";
 sleep(10);
 flock($fp, LOCK_UN);
 ?>
 
 The first script to run would obtain the lock on the file, and would
 execute.
 Any other scripts would fail immediately (because of my non-blocking
 LOCK_NB).
 
 But it seems that ALL of my scripts just wait, and ALL of them end up
 printing "Got lock!"
 
 Can anyone help me out?
 
 I am on winXP with php5.
 
 Cheers,
 Sven.
  Navigation: [Reply to this message] |