onunload when app quits - time too short

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Joakim Braun

    onunload when app quits - time too short

    Unonload doesn't get much time when quitting the browser. So how can you
    do time-consuming actions then?

    I'm doing a web-based MySQL interface. Records are presented as tables of
    links. The problem is check-in/check-out: Who can change which record when?

    So far I have a "session" approach: on login, user gets a session ID valid
    for some amount of time. Editable records have a database column for storing
    session ID:s. When user tries to open a record, we check its session ID
    column for unexpired sessions. If there are none, user gets an editable
    document that he can save back to the database, and user's session ID gets
    written to the column. If there's an unexpired session going on with the
    record, user gets a non-editable document with a "document busy" message.
    When user closes editable document, user's session ID gets cleared from the
    database record by loading a PHP page. This is triggered by the onunload
    event.

    This obviously wont work in case of crashes. It also doesn't work if user
    quits browser application: The unonload doesn't get enough time then to load
    the PHP page.

    Ideas? Design comments? (sessioning is ugly, but how else can a
    browser/database interaction be handled?)

    Joakim Braun



  • Randy Webb

    #2
    Re: onunload when app quits - time too short

    Joakim Braun wrote:[color=blue]
    > Unonload doesn't get much time when quitting the browser. So how can you
    > do time-consuming actions then?
    >
    > I'm doing a web-based MySQL interface. Records are presented as tables of
    > links. The problem is check-in/check-out: Who can change which record when?
    >
    > So far I have a "session" approach: on login, user gets a session ID valid
    > for some amount of time. Editable records have a database column for storing
    > session ID:s. When user tries to open a record, we check its session ID
    > column for unexpired sessions. If there are none, user gets an editable
    > document that he can save back to the database, and user's session ID gets
    > written to the column. If there's an unexpired session going on with the
    > record, user gets a non-editable document with a "document busy" message.
    > When user closes editable document, user's session ID gets cleared from the
    > database record by loading a PHP page. This is triggered by the onunload
    > event.[/color]

    When you check the session ID, check its age. Have a second column in
    the mySQL database that has the time the last session was issued. If
    it's expired, then disregard it and continue on as if there was no session.




    --
    Randy
    comp.lang.javas cript FAQ - http://jibbering.com/faq

    Comment

    • Fred Oz

      #3
      Re: onunload when app quits - time too short

      Joakim Braun wrote:
      [color=blue]
      > Ideas? Design comments? (sessioning is ugly, but how else can a
      > browser/database interaction be handled?)[/color]

      This is a very common database problem that has been solved a thousand
      times before. It is not really appropriate to this forum since it is
      almost entirely a server-side issue. The fact that the web is
      stateless is not really the issue, it just highlights the problem of
      updating databases in real time when real users are involved. In a
      stateful environment you know that the user's terminal is still
      connected and that they are still logged in, but you don't know if they
      are still there or actually doing something.

      The issue is if you lock a record for update, how long do you keep it
      locked for? The way around it is not to have users directly updating
      the database, they should be accessing some update function that
      does the actual update, then let business rules decide what to do.

      This may be too complex for your application, try this: grab the
      database value, then let the user modify it. When the user commits
      their change, see if the value in the database is different from when
      they checked-out the record. If so, let them know, tell them the new
      value and ask what to do. If the value is still the same, update it.

      How often you get collisions where different users try to update the
      same record can usually be estimated before hand. Try and work it out,
      and have your users approve an appropriate method of resolution. If
      the chance is low, the solution suggested above should be fine. But if
      the chance is high, you'll need something else.

      Cheers, Fred.

      Comment

      • Joakim Braun

        #4
        Re: onunload when app quits - time too short

        > Joakim Braun wrote:[color=blue][color=green]
        > > Unonload doesn't get much time when quitting the browser. So how can you
        > > do time-consuming actions then?
        > >
        > > I'm doing a web-based MySQL interface. Records are presented as tables[/color][/color]
        of[color=blue][color=green]
        > > links. The problem is check-in/check-out: Who can change which record[/color][/color]
        when?[color=blue][color=green]
        > >
        > > So far I have a "session" approach: on login, user gets a session ID[/color][/color]
        valid[color=blue][color=green]
        > > for some amount of time.[/color][/color]

        <snip>

        "Randy Webb" <HikksNotAtHome @aol.com> skrev i meddelandet
        news:BcednTOHRo MmksrcRVn-tA@comcast.com. ..[color=blue]
        > When you check the session ID, check its age. Have a second column in
        > the mySQL database that has the time the last session was issued. If
        > it's expired, then disregard it and continue on as if there was no[/color]
        session.
        <snip>

        Well, I already have session timeouts in the way you describe. But to reduce
        traffic and user annoyance I'd like to have sessions of at least 15 minutes.
        That's a long wait for a fake-"busy signal". Or do you mean a column in each
        record that says when it was opened, with a shorter timeout?

        Joakim Braun


        Comment

        • Joakim Braun

          #5
          Re: onunload when app quits - time too short

          "Fred Oz" <ozfred@iinet.n et.auau> skrev i meddelandet
          news:OVM5d.1361 $aA.50799@news. optus.net.au...

          <snip>[color=blue]
          > This may be too complex for your application, try this: grab the
          > database value, then let the user modify it. When the user commits
          > their change, see if the value in the database is different from when
          > they checked-out the record. If so, let them know, tell them the new
          > value and ask what to do. If the value is still the same, update it.[/color]
          <snip>

          Hmmm, yes - in fact I could POST the new values to a PHP script via an
          iframe in the form, instead of posting the form directly. Though another
          read access would be involved, but this will never be something with
          hundreds of users involved.

          Thanks!

          Joakim Braun


          Comment

          • Joakim Braun

            #6
            Re: onunload when app quits - time too short

            Still, the original onunload question remains. How can you meaningfully use
            unonload when it's triggered by quitting the browser?

            Joakim Braun


            Comment

            • Andrew Thompson

              #7
              Re: onunload when app quits - time too short

              On Mon, 27 Sep 2004 08:52:27 +0200, Joakim Braun wrote:
              [color=blue]
              > Still, the original onunload question remains. How can you meaningfully use
              > unonload when it's triggered by quitting the browser?[/color]

              The answer still remains that the firing of onunload is
              unreliable, so you would not (attempt to) use it for such
              functionality.

              --
              Andrew Thompson
              http://www.PhySci.org/codes/ Web & IT Help
              http://www.PhySci.org/ Open-source software suite
              http://www.1point1C.org/ Science & Technology
              http://www.lensescapes.com/ Images that escape the mundane

              Comment

              • Michael Winter

                #8
                Re: onunload when app quits - time too short

                On Mon, 27 Sep 2004 08:52:27 +0200, Joakim Braun
                <joakim.braun@j fbraun.removeth is.com> wrote:
                [color=blue]
                > Still, the original onunload question remains. How can you meaningfully
                > use unonload when it's triggered by quitting the
                > browser?[/color]

                You can't. Opera only fires the unload event when you navigate to a page.
                Refreshing or closing the tab or browser does nothing. On the other hand,
                Mozilla, Netscape, Firefox, and IE respond to all three. But, if I
                remember correctly, the first three are more restrictive regarding what
                you can do when the browser is closing.

                In any case, trying to invoke a new remote connection when the browser is
                closing is a very unreliable thing. During that time, all the browser
                should be worrying about is the freeing of resources. Acquiring new ones
                is probably not something that developers would try to accomodate. Why
                should they? It doesn't make sense.

                Mike

                --
                Michael Winter
                Replace ".invalid" with ".uk" to reply by e-mail.

                Comment

                • Joakim Braun

                  #9
                  Re: onunload when app quits - time too short


                  "Michael Winter" <M.Winter@bluey onder.co.invali d> skrev i meddelandet
                  news:opsey8v3fh x13kvk@atlantis ...[color=blue]
                  > On Mon, 27 Sep 2004 08:52:27 +0200, Joakim Braun
                  > <joakim.braun@j fbraun.removeth is.com> wrote:
                  >[color=green]
                  > > Still, the original onunload question remains. How can you meaningfully
                  > > use unonload when it's triggered by quitting the
                  > > browser?[/color]
                  >
                  > You can't.[/color]

                  <snip explanation>

                  Clear enough. Thanks for putting me off a bad track.

                  Joakim Braun


                  Comment

                  • Joakim Braun

                    #10
                    Re: onunload when app quits - time too short

                    "Andrew Thompson" <SeeMySites@www .invalid> skrev i meddelandet
                    news:190m3oshrl rhh.5trml0o67yi 0.dlg@40tude.ne t...[color=blue]
                    > On Mon, 27 Sep 2004 08:52:27 +0200, Joakim Braun wrote:
                    >[color=green]
                    > > Still, the original onunload question remains. How can you meaningfully[/color][/color]
                    use[color=blue][color=green]
                    > > unonload when it's triggered by quitting the browser?[/color]
                    >
                    > The answer still remains that the firing of onunload is
                    > unreliable, so you would not (attempt to) use it for such
                    > functionality.[/color]

                    OK, then not. Thanks.

                    Joakim Braun


                    Comment

                    Working...