#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2013
    Posts
    1
    Rep Power
    0

    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?

    TIA
  2. #2
  3. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,301
    Rep Power
    7170
    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).
    PHP FAQ

    Originally Posted by Spad
    Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around
  4. #3
  5. 'fie' on me, allege-dly
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2003
    Location
    in da kitchen ...
    Posts
    12,889
    Rep Power
    6444
    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
    --Ax
    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
    Detavil - the devil is in the detail, allegedly, and I use the term advisedly, allegedly ... oh, no, wait I did ...
    BIT COINS ANYONE

IMN logo majestic logo threadwatch logo seochat tools logo