Ask a Question related to PHP Development, Design and Development.

  1. #1

    Default implement locking

    hi,

    I would like to lock a record so that when one user is modifying a
    particular record, then it is locked for all other users. For this
    purpose, I have two fields in every table ("LockedBy int null", which
    contains the UserID of the editing user and "LockedSince int not
    null", a timestamp).

    My current logic is: when the user enters the form to modify a record,
    lock it (set LockedBy=$UserID). when the user presses the submit-button
    to commit his/her changes, unlock the record.

    The problem with this is that the user may press fwd+back buttons of
    the browser. So either I find a way to disable these in the
    editing-forms or I need to find a different way to do this

    Of course I could use a timeout (by using LockedSince-field) for cases
    where one form has been locked for > 2 hours, but that alone is not
    enough (I can't always lock records for that long!)

    thanks in advance,

    --
    Felix Natter
    Felix Natter Guest

  2. Similar Questions and Discussions

    1. Implement XFORMS on ASP
      Hi, I'm looking for a means to generate hundreds of ASP webforms using declarative language. I've put my attention on XFORMS. I understand...
    2. How to implement a MXP
      Like everything, this started simply. I want to provide breadcrumb navigation to my site. Thus after a little research I found two references:...
    3. How to implement Tracing!!
      Hello, I want to print some trace messages in my webservice. If I debug asp_net through VS.net wp I would like to see those trace messages. ...
    4. Need Direction on WHAT to Implement...
      Please understand that I am not asking HOW to do something - but, rather, I just need some advise on what "technology" or method I should...
    5. How to implement counter?
      There are many ways to do this. The low tech low impact way is the create an application variable inthe Application start, that reads in a value...
  3. #2

    Default Re: implement locking

    On Mon, 11 Aug 2003 16:06:47 +0200, Felix Natter wrote:
    > The problem with this is that the user may press fwd+back buttons of
    > the browser. So either I find a way to disable these in the
    > editing-forms or I need to find a different way to do this
    You can't.
    > Of course I could use a timeout (by using LockedSince-field) for cases
    > where one form has been locked for > 2 hours, but that alone is not
    > enough (I can't always lock records for that long!)
    That sounds wise (along with a BREAK LOCK link so that users can click it,
    see that "John Smith locked this record 50 minutes ago, do you want to
    break the lock?").

    Cheers,


    Andy
    Andy Jeffries Guest

  4. #3

    Default Re: implement locking

    Felix Natter <fnatter@gmx.net> wrote in message news:<m3ekzsxp8o.fsf@werkstatt4.ldc>...
    > I would like to lock a record so that when one user is modifying a
    > particular record, then it is locked for all other users. For this
    > purpose, I have two fields in every table ("LockedBy int null", which
    > contains the UserID of the editing user and "LockedSince int not
    > null", a timestamp).
    >
    > My current logic is: when the user enters the form to modify a record,
    > lock it (set LockedBy=$UserID). when the user presses the submit-button
    > to commit his/her changes, unlock the record.
    >
    > The problem with this is that the user may press fwd+back buttons of
    > the browser. So either I find a way to disable these in the
    > editing-forms or I need to find a different way to do this
    If you really need locking then perhaps you need to use a different
    backend database that does support row locking otherwise the best
    you'll ever achieve is a kludge.

    If you have problems with your 'locks' being released you could add to
    your logic that a lock can't be held if the user has moved off that
    page. It would still mean that if the user clicks on edit and then
    goes to lunch, goes home or closes their browser the lock would still
    be active.

    If you wanted to get really fancy you can have a page that constantly
    reports the page is open and the lock is still required.

    You place a 1px by 1px image in the page but change the source to
    refer to a PHP page, i.e. keeplock.php. You then add some JavaScript
    to the page that reloads the image every 30 seconds or so.

    In the keeplock.php, you update your locking field to reflect the new
    time and then send a header ("image/gif") and the contents of a blank
    1px by 1px gif.

    If the browser does go back or shutdown the lock will not be updated
    and you can safely release the lock.

    It still doesn't help if they leave the edit page on their browser
    when they go to lunch or go home but a smack round the head with a
    large wet tuna may help to remedy that problem.

    Paul
    Paul Liversidge Guest

  5. #4

    Default Re: implement locking

    In article <bf26a194.0308111155.40b7cf0a@posting.google.com >,
    Paul Liversidge <paul_liversidge@hotmail.com> wrote:
    >If you really need locking then perhaps you need to use a
    >different backend database that does support row locking
    >otherwise the best you'll ever achieve is a kludge.
    How would that help? The real problem is the read/update
    cycle when using a web interface. You just can't be
    sure that the user that locked the record will *ever* return
    the lock. It's not an easy problem to solve.

    --
    [url]http://www.spinics.net/lists/phpdb/[/url]

    Guest

  6. #5

    Default Re: implement locking

    Hi felix!

    On 11 Aug 2003 16:06:47 +0200, Felix Natter <fnatter@gmx.net> wrote:
    >hi,
    >
    >I would like to lock a record so that when one user is modifying a
    >particular record, then it is locked for all other users. For this
    >purpose, I have two fields in every table ("LockedBy int null", which
    >contains the UserID of the editing user and "LockedSince int not
    >null", a timestamp).
    >
    I would use optimistic locking with web interfaces. This means you
    have fields:

    "LastUpdatedBy" and "LastUpdatedDateTime"

    Also, you keep in mind when you read it for editing.

    When you save and someone else saved it meanwhile, you give a warning
    "Someone else changed the record, etc pp.". With some knowlegde about
    the table or a "before image" you may alsoi be able to merge the
    records automatically.

    HTH, Jochen
    --
    Jochen Daum - CANS Ltd.
    PHP DB Edit Toolkit -- PHP scripts for building
    database editing interfaces.
    [url]http://sourceforge.net/projects/phpdbedittk/[/url]
    Jochen Daum Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139