Re: file locking question

From: Date: Mon, 21 Jun 2004 16:42:06 +0000
Subject: Re: file locking question
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-188755@lists.php.net to get a copy of this message
> I have this script whereby I use the php function file(). > Just a quick question, do I need to implement file locking. If you want to ensure that the file is not changed by other scripts while you're reading from it, yes. Note that this is advisory only - writer scripts will only respect the lock if they request a write lock. See manual for details. > if so, can I just use something like > flock( file("/path/file.ext") ); flock() takes a file handle as an argument, not an array of strings: $fh = fopen("/path/file.ext", 'r'); flock($fh, LOCK_SH); // read from file here flock($fh, LOCK_UN); fclose($fh); See example 1 in the manual page for flock for more info. --------------------------------------------------------------------- michal migurski- contact info and pgp key: sf/ca http://mike.teczno.com/contact.html

« previous php.general (#188755) next »