Background:
I am at the initial stage of a new project built on PHP5.3. I was just starting to learn how to handle sessions in a way that initially allowed me to store sessions in a database. I am separating all session management into a separate library to facilitate transparent migration to memcached, a separate session database server, or something else the best solution by then.
I am a little confused about what would be a good approach, although there are many different ideas on the Internet about how to handle sessions depending on the version of PHP, and the more I read, the more I get embarrassed.
Question:
Here are the options that I think are most suitable. Which should I use and why? Are there other alternatives to consider?
Option 1:
Using session_set_save_handler and create custom functions for each session event in order to make full use of the built-in (built-in) processing of PHP sessions, but still save the sessions in the database. The session will be written as $_SESSION['identifier'] = 'value'; .
Option 2:
Building a complete session class that has nothing to do with PHP sessions and just acts like any database model that talks to the sessions table in my database. The session will be written as $this->sessions->write('identifier', 'value'); .
source share