mutual exclusion in PHP

Discussion in 'PHP' started by kays_f, May 14, 2010.

  1. #1
    Hi all,

    We have designed a web site as an assignment (please read the rest) and came to the final step. This step includes a concurrency control. Let me explain the situation with an example.

    In the system the user "doctor" assigns tests for a "patient", then, when any "lab technician" logs in the system he can see the patient name and the test assigned. In this case two or more technicians may try to submit the test result at the same time. For that reason we have to detect which technician clicked the submit button first (Actually it is not submit button but we have to detect which technician clicked the link of "submit result page" first). So the other results of the technicians can be rejected. We tried adding a flag attribute in the database (MySQL) but it didn't work. Then we tried a text read/write operation as a flag holder but again we were not successful. We saw a general solution called Peterson's solution but we could not manage to put it in PHP code (we have to think also multi user case of Peterson solution).

    Any kind of suggestion/help is appreciated.

    Thanks.
     
    kays_f, May 14, 2010 IP
  2. Christian Little

    Christian Little Peon

    Messages:
    1,753
    Likes Received:
    80
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Just add a timestamp field to your database then. So when the technical clicks the link and updates the database with the test result, it also stores the exact date/time they did it. Then you can review the data manually or put in some code that will go through an analyze the test results and clear up the data.
     
    Christian Little, May 14, 2010 IP
  3. kays_f

    kays_f Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Perhaps we can talk to the lecturer for this solution, but, as far as I know the resolution of the timestamp in MySQL is in seconds. IMHO, this is not a good idea for very small access times. Am I wrong?
     
    kays_f, May 15, 2010 IP
  4. gapz101

    gapz101 Well-Known Member

    Messages:
    524
    Likes Received:
    8
    Best Answers:
    2
    Trophy Points:
    150
    #4
    okay but then there is only one patient in a test result right? why not check for that patient ID or make it unique.
     
    gapz101, May 15, 2010 IP
  5. phpSiteMinder

    phpSiteMinder Peon

    Messages:
    47
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Use php's microtime() function which includes microseconds.
     
    phpSiteMinder, May 15, 2010 IP
  6. Christian Little

    Christian Little Peon

    Messages:
    1,753
    Likes Received:
    80
    Best Answers:
    0
    Trophy Points:
    0
    #6
    You can store a timestamp, which is a large integer yes. Alternatively you could use a datetime field, which stores it like this: "2010-05-15 11:41:43".
     
    Christian Little, May 15, 2010 IP