|
Posted by Efi Merdler on 03/08/07 12:14
Colin McKinnon wrote:
> Efi Merdler wrote:
>
> > Hi,
> > I created a very simple application that reads and writes to a file, I
> > was wondering if fopen when opening a file for write access blocks
> > this file, i.e. when another user runs this script the script will
> > halt until the first user closes its file handle.
> >
>
> What happenned when you tested it?
>
> Here's a hint:
> <?php
> print "ready to start\n";
> flush();
> $fh=fopen('/tmp/test','w');
> if (is_resource($fh)) {
> print "opened...\n";
> flush();
> sleep(30);
> print "Exiting\n";
> fclose($fh);
> } else {
> print "failed to open\n";
> }
> ?>
>
> (if you run two instances of this script, the second will do one of three
> things - you've only considered two possibilities so far)
>
> > If not how can I change php behavior to block such access?
> >
>
> flock()
>
> C.
Hi,
Thanks for the hint.
I tried to use a semaphore, however my php was not compiled with the
right flag, so I'm left with flock, I tested its behavior using your
scripts, it works as expected.
Efi
Navigation:
[Reply to this message]
|