LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 04-22-2003, 11:20 AM   #1
Satriani
Member
 
Registered: Mar 2003
Location: The Netherlands
Distribution: Red Hat 7.3, Red Hat 9, Solaris8, Slackware 10, Slax on USB, AIX, FreeBSD, WinXP, AIX, Ubuntu
Posts: 418

Rep: Reputation: 30
Apache, PHP and "dead" usersessions .. Anyone knows how?


Hi,

Is there a way to check if a session is "dead"?




Here's what i want:

When a user logs in I set some session variables, and write into the Database that the user-status is "online"

Next when the user exits the site, or closes the browser, I want to write into the database that the user is "offline".

Its a bit like its done here: You can see which users are in a forum. However, when I close my browser, or leave the site, the information about me being gone, must be updated. How can you check this?

I am using Apache/1.3.27 (Unix) with PHP 4.1.2

Thanks!!
 
Old 04-22-2003, 02:52 PM   #2
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,696

Rep: Reputation: 232Reputation: 232Reputation: 232
You can't check it. You need to make a user 'offline' after a timeout (10min or any other value you may find correct in your situation).
 
Old 04-22-2003, 03:47 PM   #3
Satriani
Member
 
Registered: Mar 2003
Location: The Netherlands
Distribution: Red Hat 7.3, Red Hat 9, Solaris8, Slackware 10, Slax on USB, AIX, FreeBSD, WinXP, AIX, Ubuntu
Posts: 418

Original Poster
Rep: Reputation: 30
How can i create such a timeout? (Is that a cronjob or something like that?)
Im quit new in this matter...
 
Old 04-22-2003, 04:00 PM   #4
dorian33
Member
 
Registered: Jan 2003
Location: Poland, Warsaw
Distribution: LFS, Gentoo
Posts: 591

Rep: Reputation: 32
AFIR you can do a trick. Write your HTML code using OnClose event and a JavaScript function. So when the user close the browser or change the site your function can report it to you.
 
Old 04-22-2003, 04:14 PM   #5
Satriani
Member
 
Registered: Mar 2003
Location: The Netherlands
Distribution: Red Hat 7.3, Red Hat 9, Solaris8, Slackware 10, Slax on USB, AIX, FreeBSD, WinXP, AIX, Ubuntu
Posts: 418

Original Poster
Rep: Reputation: 30
Thanks dorian, I think that the way i want to go, but then, can you help me further?
I use a mysql database, in which i keep the userstate (Just an INT for on / offline) . What can I do with the JavaScript? Or what other tricks can I do?
 
Old 04-23-2003, 01:46 PM   #6
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,696

Rep: Reputation: 232Reputation: 232Reputation: 232
You will need timeout, too. Browsers sometimes crash, users disconnect before they close browser etc. I don't know PHP very well, but I guess you need to run a loop from time to time and see if last activity time plus timeout is smaller than current time. If so, you mark the user "dead".
 
Old 04-25-2003, 08:45 AM   #7
Satriani
Member
 
Registered: Mar 2003
Location: The Netherlands
Distribution: Red Hat 7.3, Red Hat 9, Solaris8, Slackware 10, Slax on USB, AIX, FreeBSD, WinXP, AIX, Ubuntu
Posts: 418

Original Poster
Rep: Reputation: 30
Thanx for the input so far...

But its indeed this time-out thingie: Who runs this? I guess some kind of script on the server, and not particularly a webserver/webpage/php script ??????

I indeed want to do something like this:

currentTime>lastActiveTime+timeOut?userLoggedOff:doNothing

But lastActiveTime is set by who? And this timeOut, where to put that? And then the script to run: Where to put that?

As you see alot of questions.........

Sorry for my l8 replies, but I am not always able to respond right away, but I always will respond!!!

Thanks in advance for anyone who helps me further!
 
Old 04-25-2003, 04:15 PM   #8
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,696

Rep: Reputation: 232Reputation: 232Reputation: 232
It can be another process (one that wakes up only to check timeouts and then sleeps). The timeout may be set in a config file/databese entry.
 
Old 04-26-2003, 07:31 PM   #9
Satriani
Member
 
Registered: Mar 2003
Location: The Netherlands
Distribution: Red Hat 7.3, Red Hat 9, Solaris8, Slackware 10, Slax on USB, AIX, FreeBSD, WinXP, AIX, Ubuntu
Posts: 418

Original Poster
Rep: Reputation: 30
Mara,

I still am lost here.... Is it some cron-process that should check this, or is there some other trick? I really have no clue where to start...

Can you help me to start somewhere???
 
Old 04-27-2003, 09:59 AM   #10
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,696

Rep: Reputation: 232Reputation: 232Reputation: 232
It may be a separate program started by cron. Or a prog that runs 'sleep(delay)' (or similar instruction, depending on the language you use to write it) after work is done, after a delay it wakes up and starts its work, then sleeps ans do on. I think a cron prog will be better.
 
Old 04-28-2003, 12:53 AM   #11
Obi Perrin
Member
 
Registered: Nov 2002
Posts: 136

Rep: Reputation: 15
If I was doing it, I'd have the 'online' and 'last_active' fields in my database. As the logged in user moves from page to page, the last_active is updated to the timestamp of when the page was served. Then, when you're creating your "Who's Online" box or whatever, you check the database for all users who are online, and have a 'last_active' time within the last e.g. 10 mins, display all of them. Those who are 'Online', but outside of the 10 mins are set to False in the 'online' field .

A cron job may or may not be more efficient. Haven't tried it before so I'm not sure.
 
Old 04-28-2003, 09:26 AM   #12
Satriani
Member
 
Registered: Mar 2003
Location: The Netherlands
Distribution: Red Hat 7.3, Red Hat 9, Solaris8, Slackware 10, Slax on USB, AIX, FreeBSD, WinXP, AIX, Ubuntu
Posts: 418

Original Poster
Rep: Reputation: 30
Thanks Obi,

I now have a good idea of where to start! Just if you were curious how, and maybe for all others:

I will add the online and last access time to the database.
Next I will create a php-script something like showOnline.php

In this script I will check all entries in the database who have the status Online = true.
All these entries will be checked on their last access time. If it exceeds the MAX_TIMEOUT (i.e. 10 minutes), this script will update the database, and set Onlinestatus to false.

Now i include this script in every page on the site. So, the updating is done by the next user who gets to the site. (Or every time a user gets to another page on the site. )
I am aware of the amount of database activity this will cost, but what the heck, it's a very small site anyway. If it was intended for more than 1000 users a day, I would use something else than just PHP and mySQL. (Something like websphere... )

Thanks for your help and ideas!!!

Satch
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Exactly how do I make a "dead image" of a drive? abefroman Linux - Security 7 08-03-2005 05:29 PM
Conexant Winmodem session "dead" after login Gert2 Linux - Hardware 1 02-16-2004 04:04 PM
Error: "mysqld dead but subsys locked" mikeshn Linux - Software 1 01-01-2004 05:18 PM
Define "dead ethernet card" please. wuck Linux - Networking 10 10-26-2003 09:58 PM
php ide with "break" and "trace" Kayaker Programming 3 04-25-2003 02:52 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 02:05 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration