|
Posted by LetsSurf on 09/22/06 08:27
I think you need to open the file with w+ e.g. $fp = fopen("foo.txt",
"w+");
Give it ago see what happends, I might be wrong.
sven.holcombe@gmail.com wrote:
> 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]
|