LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Networking (https://www.linuxquestions.org/questions/linux-networking-3/)
-   -   Apache, PHP and "dead" usersessions .. Anyone knows how? (https://www.linuxquestions.org/questions/linux-networking-3/apache-php-and-dead-usersessions-anyone-knows-how-56278/)

Satriani 04-22-2003 11:20 AM

Apache, PHP and "dead" usersessions .. Anyone knows how?
 
Hi,

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

:scratch:


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!!

Mara 04-22-2003 02:52 PM

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

Satriani 04-22-2003 03:47 PM

How can i create such a timeout? (Is that a cronjob or something like that?)
Im quit new in this matter...

dorian33 04-22-2003 04:00 PM

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.

Satriani 04-22-2003 04:14 PM

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?

Mara 04-23-2003 01:46 PM

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

Satriani 04-25-2003 08:45 AM

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!

Mara 04-25-2003 04:15 PM

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.

Satriani 04-26-2003 07:31 PM

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???

Mara 04-27-2003 09:59 AM

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.

Obi Perrin 04-28-2003 12:53 AM

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.

Satriani 04-28-2003 09:26 AM

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


All times are GMT -5. The time now is 07:03 PM.