HOW TO: get list of active sessions of my domain

Discussion in 'PHP' started by ivo.pavlik, Jan 21, 2009.

  1. #1
    Hello.

    I'd like to know if it is possible to get list of active sessions of domain my script is running on. I want to clear data of inactive sessions on disk, e.g. data which remained after some error, when client can't send request for cleanup. Some script would be launched periodically and if session with some id isn't in alive sessions, data will be deleted.
    If I could catch an event, when a session is beeing disabled, it would be great :D.

    Thanks for any suggestions.
     
    ivo.pavlik, Jan 21, 2009 IP
  2. r0kawa

    r0kawa Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    For this to works. you need to do a database session setting. Google: 'PHP database sesssion' . If you change default PHP session from file to database. All the session will be list on your specified table. After that, maybe you can include extra fields, like username where you can detect which username link to which session, and you can disable and delete the session you want.
     
    r0kawa, Jan 22, 2009 IP
  3. phper

    phper Active Member

    Messages:
    247
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #3
    It's already handled by PHP's garbage collector, so you don't need to bother.

    But if you are in an emergency need to do it, just remove those with older 'last modified' time. Check your php.ini file for the config: 'session.gc_maxlifetime' and make sure you don't delete files newer than that.
     
    phper, Jan 22, 2009 IP
  4. Curtis004

    Curtis004 Guest

    Messages:
    29
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Correct me if I am wrong but,

    If you save the session data to a file using session_encode(); or serialise you should be able to call it back out when you need it, just an idea
     
    Curtis004, Jan 23, 2009 IP
  5. joebert

    joebert Well-Known Member

    Messages:
    2,150
    Likes Received:
    88
    Best Answers:
    0
    Trophy Points:
    145
    #5
    What you can do depends on your session_save_handler for starters.

    If you're using the default file-based handler and can setup a cron job that has access to your session_save_path, you can probably just setup a cron job that runs once every X minutes/etc and executes a find command that deletes files in that directory with an access or last modified timestamp older than X minutes/etc.
     
    joebert, Jan 23, 2009 IP
  6. ivo.pavlik

    ivo.pavlik Member

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #6
    That looks like something I was searching for. I'm surprised of a direct way. Will look for some way to use default save behavior. I need only catch destroying event with a handler. Thanks.
     
    ivo.pavlik, Jan 26, 2009 IP
  7. ahmademam81

    ahmademam81 Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    thank you very much
     
    ahmademam81, Jan 31, 2009 IP