You are here: Re: Blocking with fopen when file is already open for writing « PHP Programming Language « IT news, forums, messages
Re: Blocking with fopen when file is already open for writing

Posted by Efi Merdler on 03/04/07 11:12

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.

Thanks,
I'll probably use a semaphore in order achieve this block behavior.

Efi

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация