|
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]
|