You are here: Re: flock won't non-block at all « PHP Programming Language « IT news, forums, messages
Re: flock won't non-block at all

Posted by Andy Hassall on 09/22/06 21:00

On 22 Sep 2006 09:30:54 -0700, "NC" <nc@iname.com> wrote:

>This is the bad news. The good news is that you don't necessarily
>need flock() for this. Here's a possible workaround:
>
>$file = 'foo.txt';
>if (file_exists($file)) {
> $time = date('Y-m-d H:i:s', trim(file_get_contents($file)));
> die('Another instance is running since ' . $time);
>}
>$fp = fopen($file, 'w');

Although the fun then begins when you hit the (admittedly short-duration) race
condition here...

>fwrite($fp, time());
>fclose($fp);
>// the script goes here...
>unlink($file);

... or the never-released lock when the script dies before reaching here :-(

--
Andy Hassall :: andy@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool

 

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

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