troks
troks

Reputation: 91

Is it necessary to change session.save_handler when using session_set_save_handler

I'm storing the session data in a database. In class Session are storage functions which are used for storing and retrieving data.

Now my question's are:

Do I need to change the value of session.save_handler in runtime configuration as default is set to 'files', or does the function session_set_save_handler overrides(ignores) that?

And what if session.auto_start is enabled, which handler is used then?

Here's the minimized version of my class session:

class Session
{

public function __construct($registry, $sessionhash = '', $userid = 0, $password = '')
{
    $this->config = cl_Config::instance();
    $this->db = cl_Database::instance($this->config);
    $this->hasher = cl_Hasher::instance();

    // Register this object as the session handler
    session_set_save_handler( 
        array( $this, "open" ), 
        array( $this, "close" ),
        array( $this, "read" ),
        array( $this, "write"),
        array( $this, "destroy"),
        array( $this, "gc" )
    );

function open( $save_path, $session_name )
{
    ...
    return true;
}

function close( $save_path, $session_name )
{
    ...
    return true;
}

function read( $id )
{
    ...
}

function write( $id, $data )
{
    ...
    return true;
}
...

Upvotes: 0

Views: 1299

Answers (1)

Wrikken
Wrikken

Reputation: 70510

No you don't to set session.save_handler if you call session_set_save_handler(), but with auto_start the default configured one will start (built-in or supplied by modules), not your user supplied one. About the auto-start: it may seem like a nice idea, but keep in mind opening a session blocks all other requests starting a session until it finishes. So best start sessions only when you need them.

Upvotes: 1

Related Questions