You are here: Re: question about using lock files « PHP Programming Language « IT news, forums, messages
Re: question about using lock files

Posted by Andy Jeffries on 05/04/06 22:01

On Thu, 04 May 2006 09:30:13 -0700, Sjoerd wrote:
>> To prevent two users from
>> getting the same serial number I put a delay loop in the script using
>> while(file_exists(tracknum.lock)
>
> You have a typical race condition:
>
> You wait until the file is deleted and then create it. Suppose that the
> file is deleted and created immediatly after file_exists. The file would
> be created by another process, e.g. another user requesting this page.
> After the while() loop, you assume that the file still does not exist in
> the next instruction, which is an unfair assumption.

From what I remember when studying for the ZCE, mkdir is atomic and
returns true or false as to whether the directory was created or not - and
hence is the best choice for locking...

Cheers,


Andy

--
Andy Jeffries MBCS CITP ZCE | gPHPEdit Lead Developer
http://www.gphpedit.org | PHP editor for Gnome 2
http://www.andyjeffries.co.uk | Personal site and photos

 

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

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