Reply to Re: flock won't non-block at all

Your name:

Reply:


Posted by Sven on 09/26/06 00:25

> >Andy Hassall wrote:
> >>
> >> > $fp = fopen($file, 'w');
> >>
> >> Although the fun then begins when you hit the (admittedly
> >> short-duration) race condition here...
> >
> >You are absolutely right, but how else could you work around the file
> >locking issue on Windows?
>
> Not sure whether there's anything convenient in PHP itself that'll give you a
> per-thread reliable and atomic lock. The win32 API has plenty of
> synchronisation functions that would work, perhaps one could be called using
> the win32api extension?
>
> In some situations where I've needed locks and have had to work across Windows
> and NFS filesystems (which have their own file locking quirks) I've used locks
> within a database (user-defined locks in Oracle) - but in those cases I was
> connecting to a database already.

Thanks for the tips guys, here's a rundown of the end result:
It turns out that whenever I was testing my little example above, I was
opening the script through a browser. For some reason the flock() never
seems to work for me this way, however when I ran it from the
command-line php things sorted themselves out. My application was
going to run in the background anyway, so I've ended up getting it to
work by having my web php call command-line php as a background
process.

The file check/create/unlink option is a good one, but my script is one
that will fire occassionaly, but will sit in a while loop for hours at
a time. So, the dead-script problem is a real one here.

Cheers for the input people,
Sven.

[Back to original 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

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