Re: File locking issues
| From: | Manuel Lemos | Date: | Wed, 05 Jan 2000 23:58:48 +0000 |
| Subject: | Re: File locking issues | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-14294@lists.php.net to get a copy of this message | ||
Hello Sascha,
On 04-Jan-00 12:37:43, you wrote:
>> Since we have to pass an opened file handle to flock(), if the file
>> is closed with a pending lock, is that lock freed?
> File descriptors are closed either explicitly by the program
> or on process termination.
> PHP's flock inherits the semantics of the underlying
> implementation.
Ok, thanks. What about in the Windows world? Does it work alike?
Another question. What is the recomended sequence to assure that only a
access will be able to write to a file at once?
What I am doing is:
1) $file=fopen($filename,"w");
2) flock($file,2);
3) fwrite($file,...)
4) flock($file,3);
5) fclose($file)
Could two processes get to 2) and have one overwrite what the other just
wrote to the file?
To read I do:
1) $file=fopen($filename,"r")
2) flock($file,1);
3) fread($file);
4) flock($file,3);
5) fclose($file);
I suppose this prevents a process to write to the file while it is written
with the former access sequence while one or more processes are reading
from the file with the later access sequence. I wonder if my concurrency
analisys is correct.
Regards,
Manuel Lemos
Web Programming Components using PHP Classes.
Look at: http://phpclasses.UpperDesign.com/?user=mlemos@acm.org
--
E-mail: mlemos@acm.org
URL: http://www.mlemos.e-na.net/
PGP key: http://www.mlemos.e-na.net/ManuelLemos.pgp
--