473,545 Members | 2,715 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1702
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.javas cript 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******** ************@co mcast.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.n et.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**********@j fbraun.removeth is.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.******@bluey onder.co.invali d> skrev i meddelandet
news:opsey8v3fh x13kvk@atlantis ...
On Mon, 27 Sep 2004 08:52:27 +0200, Joakim Braun
<jo**********@j fbraun.removeth is.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.ne t...
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
6946
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 user closes the popup, it sends a request to my web server (GoAhead) using the onunload event, then closes the popup. For the moment, this what i...
2
1635
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 window that will open is a survey for a webcast they just viewed. I can't put the script in the header or place a onUnload command in the body tag....
3
5864
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 third-party component (think of it as a lock) when the page loads. Now the OK and Cancel server buttons I can handle and use to release the lock as...
3
1442
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 is that every time I initiate a postback, the event is also fired. I dont want people to see "Are you sure you wish to discard any changes?" if they...
4
1205
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 players. Since a changed the server (from Windows 2003 32 Bit, 2GB RAM) to a new Server "Windows 2003 64 Bit, 4 CPU's, 8 GB RAM) and upgraded the...
1
1510
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" in the <scripttag. However, when I do that, it launches foo as soon as the page loads and does NOT launch when the page is unloaded.
0
11814
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 init() is a function which initialises some variables (for example).
3
2371
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 Counter-Strike (CS) a lot, but I'm limited to 2 ½ hours a day, and a total of 4 hours a day. I have one button in my program which starts CS, and one button...
0
7499
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7943
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7456
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7786
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5359
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5076
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
1919
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1044
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
743
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.