Well I'm sure others might refute it, but I think you're getting into the
internals of PHP and programming languages in general, which while not
exactly outside the scope of the list, might be asking a little too much of
it. I mean, the answer to number 1) is simply to put together a script that
uses flock() and to simulate two users trying to open the file at the same
time (which would I guess be quite hard really), but personally I tend to
take the developers word about these things, and assume that if the manual
says the file is locked and the second process has to wait, it'll work. If
you're getting into _why_ or _how_ it works, you really need to look at the
source or talk to the developers. Same goes for questions 2) and 3). As to
question 4), the simple answer is "when you use another file locking
mechanism", such as the traditional route of using a lockfile. But of course
that has questions of its own, like "what about when two processes try to
access the /lockfile/ at the same time". What I'm trying to say is that if
you want an in-depth explanation of how flock() - or anything else - works
in PHP, I think you might be better off asking on the PHP mailing list or
the even the developers list. But I guess I could be wrong. Maybe someone
else will pop along in a minute and explain it in detail... :)
> -----Original Message-----
> From: webdev-admin at linux.ie [mailto:webdev-admin at linux.ie]On Behalf Of
> Gabe Petrie
> Sent: 1 May 2001 01.06
> To: webdev at linux.ie> Subject: [Webdev] revisiting flock() for an example
>>> i had one question i set out to be asked... namely... given file "F" (of
> content "F"), simultaneously accessed by both users "1" and "2" (each of
> them appending content "1" and content "2") , how do I end up
> with a file of
> "F"+"1"+"2" and not just "F"+"1" or "F"+"2" or just "F" or even "foobar" ?
>> namely, how do I lock "fp $file" while "dirty_work(fp $file)" is
> being done
>> well use of flock() was suggested, but the documentation is not
> clear about
> what exactly happens when I use flock() or how exactly I should
> use it for a
> given instance. and, having found out that flock() is what I should use, a
> few more questions arise.
>> I would really enjoy (and i think others might also enjoy) having all the
> following questions answered verbosely or concisely as you see fit!
>  Can I see an example code of flock() in action for a
> situation where two
> users are going to possibly access the same file simultaneously, both of
> them attempting to read and view its contents at once, and both of them
> attempting to write their own appended and/or inserted (processed)
> content -- simultaneously? in other words, an example of using flock() for
> when dirty_work($file) must force one_user to wait while the_other_user is
> doing dirty_work() ?
>>  your own preferred explanation for what happens on a hardware
> level when
> flock is used ?
>>  your own preferred explanation for what happens on a software
> level when
> flock is used ?
>>  situations when using flock() is not necessary ?
>> thank you Ahead Of Time for every piece of help you provide. this is the
> first time i've had to leave the manual and ask somebody else for
> PHP help.
>> if you want to know, my problem is that i have designed a message
> forum that
> stores all messages in a single file, maintaining hierarchy
> through a number
> assigned to each entry. i need to insure that if two users access the file
> at the same time to write their entries to it (even if the disk process
> takes a total of 17 milliseconds) that what was intended to
> happen happens,
> and not something messy and embarassing.
>> -gabriel arthur petrie
>gabriel at arq.net>> --
> DuuuuUUUUuuuuUUUUuuuude !
> Webdev mailing list
>Webdev at linux.ie>http://www.linux.ie/mailman/listinfo/webdev>
Maintained by the ILUG website team. The aim of Linux.ie is to
support and help commercial and private users of Linux in Ireland. You can
display ILUG news in your own webpages, read backend
information to find out how. Networking services kindly provided by HEAnet, server kindly donated by
Dell. Linux is a trademark of Linus Torvalds,
used with permission. No penguins were harmed in the production or maintenance
of this highly praised website. Looking for the
Indian Linux Users' Group? Try here. If you've read all this and aren't a lawyer: you should be!