RE: [PHP] File Locking during *other* file operations

From: Date: Mon, 20 Dec 2004 18:26:29 +0000
Subject: RE: [PHP] File Locking during *other* file operations
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-204743@lists.php.net to get a copy of this message
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

« previous php.general (#204743) next »