August 1st, 2013, 09:47 AM
Flock with 12 users
I have a simple CGI script that writes to a text file (chat room, basically). Since 12 or more users could be chatting at once, my question is this: are all users put in queue and sent to my text file one at a time, once each FLOCK is released?
Example: FLOCK engaged; User 1 writes to text file. FLOCK released. User 2 is next, and allowed to write to text file. And so on.
My concern is that a) if FLOCK is engaged, and only 1 user can write, the other users in the queue will be dropped. Unfounded?
August 1st, 2013, 05:54 PM
If the file is locked, a call to flock will normally block until the original lock is released. However, if multiple processes are currently blocked on an flock call, I do not believe there is any guarantee as to which will receive the next lock (ie: it's not a queue).
August 2nd, 2013, 08:37 AM
Word of warning, IIRC flock is not implemented on windows
Can you use a database to avoid flocking altogether? I wouldn't consider flock to be a good strategy with 12 users, 2 maybe, but because it's not a queue or round robin system, there's no way of determining next to get in after the flock, eg one process could flock the file 3 times, whilst one other process is still awaiting a release
without exception, there is no rule ...
Handmade Irish Jewellery
Targeted Advertising Cookie Optout (TACO) extension for Firefox
The great thing about Object Oriented code is that it can make small, simple problems look like large, complex ones
09 F9 11 02
9D 74 E3 5B
D8 41 56 C5
63 56 88 C0
Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems.
-- Jamie Zawinski
- the devil is in the detail, allegedly, and I use the term advisedly, allegedly ... oh, no, wait I did ...
BIT COINS ANYONE