RE: [PHP] File Locking during *other* file operations
| From: | Robinson, Matthew | Date: | Thu, 23 Dec 2004 09:35:01 +0000 |
| Subject: | RE: [PHP] File Locking during *other* file operations | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-205049@lists.php.net to get a copy of this message | ||
No really good reason that I can think of. I don't see any reason as to
why it wouldn't work with just 'x'.
Must have been having a 'beer' moment.
yes, it should probably clear out stale lock files but the files I
protect with this are better left untouched if the lock fails. I think
that locks fail for a reason and you should find that reason before you
unlock and potentially break something.
M
-----Original Message-----
From: Richard Lynch [mailto:ceo@l-i-e.com]
Sent: 20 December 2004 18:26
To: Robinson, Matthew
Cc: Michael Sims; php-general
Subject: RE: [PHP] File Locking during *other* file operations
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
________________________________________________________________________
This message has been checked for all known viruses by the
CitC Virus Scanning Service powered by SkyLabs. For further information
visit
http://www.citc.it
___
________________________________________________________________________
This message has been checked for all known viruses by the
CitC Virus Scanning Service powered by SkyLabs. For further information visit
http://www.citc.it
___