RE: File Locking during *other* file operations

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Robinson, Matthew wrote:
>  I use this code, Not all my own, some from the php manual (probably
> most of it in fact) I lock the file as filename.lock so that I can muck
> about with it completely and then unlock the .lock and remove it.
>
> M
>
> function LockFile($file)
> {
>
>         $LockFile = $file . ".lock";                    # Lock the file
>         $lf = fopen ($LockFile, "wx");
>
>         while ($lf === FALSE && $i++ < 20)
>         {
>                 clearstatcache();
>                 usleep(rand(5,85));
>                 $lf = @fopen ($LockFile, 'x');


How come you use "wx" up there, and just 'x' here?

Is there some reason for that?

One may (or may not) want to consider a mechanism for throwing out really
old lock files, since it's possible your PHP script or application would
eventually fail to remove a lock file...  Or not, depending on how you
code the rest of it.

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux