473,395 Members | 1,915 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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

Jul 23 '05 #1
9 1693
Joakim Braun wrote:
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.


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.javascript FAQ - http://jibbering.com/faq
Jul 23 '05 #2
Joakim Braun wrote:
Ideas? Design comments? (sessioning is ugly, but how else can a
browser/database interaction be handled?)


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.
Jul 23 '05 #3
> Joakim Braun wrote:
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.

<snip>

"Randy Webb" <Hi************@aol.com> skrev i meddelandet
news:Bc********************@comcast.com... 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.
<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
Jul 23 '05 #4
"Fred Oz" <oz****@iinet.net.auau> skrev i meddelandet
news:OV*****************@news.optus.net.au...

<snip>
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.

<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
Jul 23 '05 #5
Still, the original onunload question remains. How can you meaningfully use
unonload when it's triggered by quitting the browser?

Joakim Braun
Jul 23 '05 #6
On Mon, 27 Sep 2004 08:52:27 +0200, Joakim Braun wrote:
Still, the original onunload question remains. How can you meaningfully use
unonload when it's triggered by quitting the browser?


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
Jul 23 '05 #7
On Mon, 27 Sep 2004 08:52:27 +0200, Joakim Braun
<jo**********@jfbraun.removethis.com> wrote:
Still, the original onunload question remains. How can you meaningfully
use unonload when it's triggered by quitting the
browser?


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.
Jul 23 '05 #8

"Michael Winter" <M.******@blueyonder.co.invalid> skrev i meddelandet
news:opsey8v3fhx13kvk@atlantis...
On Mon, 27 Sep 2004 08:52:27 +0200, Joakim Braun
<jo**********@jfbraun.removethis.com> wrote:
Still, the original onunload question remains. How can you meaningfully
use unonload when it's triggered by quitting the
browser?


You can't.


<snip explanation>

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

Joakim Braun
Jul 23 '05 #9
"Andrew Thompson" <Se********@www.invalid> skrev i meddelandet
news:19****************************@40tude.net...
On Mon, 27 Sep 2004 08:52:27 +0200, Joakim Braun wrote:
Still, the original onunload question remains. How can you meaningfully use unonload when it's triggered by quitting the browser?


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


OK, then not. Thanks.

Joakim Braun
Jul 23 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Laurent | last post by:
I am trying to use the onunload event to know when the user closes a popup by receiving a request on the web server. I have a main page from where the user opens a popup. What I want is when the...
2
by: Rich | last post by:
Is there any way to get the same effect that the body tag onUnload creates. I need a script that will be placed in the body of the html that will open a new window when the parent is closed. The...
3
by: =B= | last post by:
Hi all, I was wondering if anyone has had any luck with trapping the <BODY> onUnload() event in ASP.NET? The thing is, I'm writing code for an Intranet site. The code makes a call to a...
3
by: Weston Weems | last post by:
Ok, what I am attempting to do is take a web form and attach a confirm to leave page. I can get the event to fire (though it doestn actually prevent navigating away from the site) My problem...
4
by: Sebastian Loncar | last post by:
Hallo NG, i've big online game with a lots of requests per second and it uses a lot of memory. the game runs as an ASP.NET application and holts all the game data in the memory. The game has 1600...
1
by: Tim Arview | last post by:
Hi, I'm trying to create an exit popup that doesn't require anything added to the body tag. In other words, I don't want to say <body onunload="foo">. I just want to have window.onunload="foo"...
0
acoder
by: acoder | last post by:
Problem onload and onunload events do not fire when going back, forward or refreshing the page Browser Opera Example Any code using onload or onunload, e.g. window.onload = init; where...
3
by: Saser | last post by:
Hi all bytes out there. I have a few little problems in my program. The program is supposed to help me to not spend too much time of my day at the computer ;) I play a game called...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.