1

I need to see all the sessions which are active on my webpage, After some searching i came across a function session_status() which is included in php 5.4, which i guess tells active sessions. But till now i am not able to figure out how to use this function. Can Anyone tell how to use this function with a example. I have php 5.4 installed on my system, so that is not an issue.

Sibu
  • 4,609
  • 2
  • 26
  • 38
  • PHP (5.4 or any version) does not have a built-in function `session_status()`. Where did you find this information? – Jordan Running Oct 19 '11 at 04:07
  • @Jordan i read that on stackoverflow http://stackoverflow.com/questions/3788369/how-to-tell-if-a-session-is-active – Sibu Oct 19 '11 at 04:11
  • Well that explains why it's not documented yet--5.4 is still in prerelease. You seem to have misunderstood the purpose of this function, however. It does not tell you anything about all of the "active" sessions--it only tells you the status of the current session, i.e. the session belonging to the user that is viewing the page. – Jordan Running Oct 19 '11 at 04:40
  • What makes your question different from the possible duplicate [Find Number of Open Sessions](http://stackoverflow.com/questions/679657/find-number-of-open-sessions)? – hakre Nov 08 '11 at 12:46

4 Answers4

1

As far as I know, there is no automatic way to do this. One simple way is to look in your tmp directory that the PHP sessions are being written to and count how many files are there (assuming sessions are being stored in file).

endyourif
  • 2,186
  • 19
  • 33
  • This can work, but keep in mind that the file will still be there for a while after the user closes their browser or navigates elsewhere. You would need to set sessions to expire after a very short time to make this accurate. Then you have to keep those sessions alive when a page is still open, which can be done by repeated ajax calls every x seconds. – Syntax Error Oct 19 '11 at 05:32
0

The point is that it is impossible to see all the sessions which are active, you can't tell whether the session is active or not. If the user close the page without do any operation like logout, the session info (session files or other storage) is still remained in server and wait for session GC to clear it.

xdazz
  • 158,678
  • 38
  • 247
  • 274
0

PHP.net -> Session_Status This Funktion doesn't exist in PHP, that must be a selfmade funktion of this Person. I think this is not possible whitout a other programm like a shell script or something like that.

The link above from you, looks like a php5.4 extendsion that you must install manuell.

San
  • 868
  • 1
  • 9
  • 18
  • 1
    I have php 5.4 installed on my system and function is working and it is not showing any error. So the function exists – Sibu Oct 19 '11 at 06:20
  • Then PHP.NET this has probably not updated yet. I think that it is not possible, the query sessions in PHP. Unless you look in this folder after session, but closed sessions are not deleted immediately, I think. If you find another way I'm excited? – San Oct 19 '11 at 08:11
0

This is a pain, but it's possible. Aside from counting the session files as endyourif mentioned, you could have all active sessions update their ip address or user id and also a timestamp in a database table every 30 seconds or so (via ajax). You would then be able to query how many users were active within the previous x seconds at any time.

This could eat up resources faster than usual so be careful if you get a lot of traffic. Using a memory table might help. Also you would want to run a cron job every so often to clean out entries that are no longer needed, for example anything older than 15 minutes.

Syntax Error
  • 4,475
  • 2
  • 22
  • 33