Leaving a website

This forum is now closed as part of retiring phpBB2.
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

This forum is now closed due to phpBB2.0 being retired.
Post Reply
User avatar
Hater
Registered User
Posts: 570
Joined: Tue May 06, 2003 8:56 pm
Location: Wisconsin
Contact:

Leaving a website

Post by Hater »

I googled and snooped around but came up short, so I come here for some help.

Can anyone point me towards an example or idea, to see if it is possible to envoke code when someone leaves your website? Either when closing the window or visiting another site.

My theory is to have smart sessions that can clean up after themselves when someone leaves, and the only way I can think to do this is somehow kill the session when the user leaves.

To me, community garbage collection just seems so inefficient. When I eat food in the lunch room, I don't want to clean up after someone that left their food there just so someone can clean up after me when I leave; everyone should clean up after themselves the same as I do. Having a new user or guest clean up sessions on their session creation is a great way to do things but still seems, I dunno, wrong.

This could potentially eliminate the garbage collection method all together, which is eventually what I'm aiming for.
User avatar
Hater
Registered User
Posts: 570
Joined: Tue May 06, 2003 8:56 pm
Location: Wisconsin
Contact:

Post by Hater »

Hmm.. Did find a javascript version, which may be okay but I still will have to run a garbage collection within a set interval of time. Hmm..
Dman8568
Registered User
Posts: 32
Joined: Sun Feb 20, 2005 4:00 am
Location: WV, USA
Contact:

Post by Dman8568 »

The only function for this , that I know of, is in Javascript. The "Unload" event gets trigered whenever the user leaves the page

However, I don't think this would help because Javascript can't exicute SQL Statments on the Database.
- Dman8568

My MODs:
- UserGroup E-Mail Switch MOD
WeAz
Registered User
Posts: 46
Joined: Tue May 04, 2004 2:30 pm
Location: CA
Contact:

Post by WeAz »

Dman8568 wrote: The only function for this , that I know of, is in Javascript. The "Unload" event gets trigered whenever the user leaves the page

However, I don't think this would help because Javascript can't exicute SQL Statments on the Database.

You could if you were using AJAX, I'm sure. Might be worth investigating.

-WeAz
User avatar
drathbun
Former Team Member
Posts: 12204
Joined: Thu Jun 06, 2002 3:51 pm
Location: TOPICS_TABLE
Contact:

Post by drathbun »

If you don't want one user to "clean up" after another user, you could set up a cron job that runs every five minutes and cleans up unused sessions. That would allow you to remove that "clean up" code from the sessions.php code, but would require an external process.

The up side is that you've removed code from sessions. The down side is that your clean up code runs 24x7, where sessions is only executed when someone is actually on your board. To be honest, there are never really that many rows in the sessions table... I don't think I would try to change it. If you are experiencing performance issues, an index on session_time would probably help. That's what's used in the delete query:

Code: Select all

                                        $sql = "DELETE FROM " . SESSIONS_TABLE . "
                                                WHERE session_time < $expiry_time
                                                        AND session_id <> '$session_id'";
I blog about phpBB: phpBBDoctor blog
Still using phpbb2? So am I! Click below for details
Image
User avatar
Hater
Registered User
Posts: 570
Joined: Tue May 06, 2003 8:56 pm
Location: Wisconsin
Contact:

Post by Hater »

Not experiencing any performance issues at all actually, just experimenting with some ideas. :)
Post Reply

Return to “[2.0.x] MOD Writers Discussion”