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 . Thanks for any suggestions.
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.
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.
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
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.
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.