I am thinking of implementing database-driven session management in PhP and have read on the session_set_save_handler function to specify the callbacks to be triggered on different session-based events. There is also the option to implement an interface. In fact there is a lot of info if you google around. I state all this because my question is not HOW to use session_set_save_handler() to implement a db-driven session management solution but rather HOW to implement the same functionality without using it.
What I was wondering is why go through the session_set_save_handler at all? How about an intermediate approach? Just use the session handling in PhP to get the session id and then using this as the key, one can implement a full CRUD functionality on session variables (of course, not connected to the $_SESSION array). For example, use another associative array as in $_DBSESSION. After session is started, get the session id and retrieve all rows in DB with this key and populate the $_DBSESSION array and when session is to be closed, this array is dumped, one record per array index into the database table after first deleting all entries with that session id. This write-to-db functionality can be in the register_shutdown_function() as it is done last when the program exits. Garbage cleanup can be done separately following whatever custom approach is needed.
This way, one can use the built-in $_SESSION array also conventionally along with the $_DBSESSION approach. This sounds a lot less complex than the use of the session_set_save_handler(). Also, the actual session creation in terms of cookie interface is still taken care of by PHP's session management.
QUESTION: Am I on the right track? Does this make sense?