Page 1 of 1

Why would session_set_save_handler not work?

Posted: Tue Dec 19, 2006 6:38 pm
by Luke
Can anybody think of a reason why session_set_save_handler might not work? I am using Zend_Session which is still in the framework's incubator, but as far as I know, it's as simple as this:

Code: Select all

static public function setSaveHandler(Zend_Session_SaveHandler_Interface $interface)
    {

        session_set_save_handler(
            array(&$interface, 'open'),
            array(&$interface, 'close'),
            array(&$interface, 'read'),
            array(&$interface, 'write'),
            array(&$interface, 'destroy'),
            array(&$interface, 'gc')
            );
    }

Code: Select all

Zend_Session_Core::setSaveHandler(
            new MC2_Session_Mysql($db)
        );
Although the component is in the incubator, I find no reason why this shouldn't work. I've implemented Zend_Session_SaveHandler_Interface, and I've tested that each of my methods within that class work as they are supposed to. Am I missing something?

Posted: Tue Dec 19, 2006 6:40 pm
by Weirdan
AFAIK user-defined session handler has to be allowed explicitly in php.ini

Posted: Tue Dec 19, 2006 6:49 pm
by Luke
the only config option I see that relates to it is session.save_handler (which is set to files). I've set up a custom session save handler on a shared server before... :?

Posted: Tue Dec 19, 2006 6:54 pm
by Weirdan
this directive should include 'user' for custom session handlers to work

Posted: Tue Dec 19, 2006 6:58 pm
by Luke
Are you sure? I don't remember having to change any directives on my shared host which I know for a fact is using a custom save handler I wrote a little while back. This is the error I got when I changed "files" to "user"
Fatal error: session_start() [<a href='function.session-start'>function.session-start</a>]: Failed to initialize storage module: user (path: C:\php5.2.0\tmp) in C:\myfile.php on line 5

Posted: Tue Dec 19, 2006 7:01 pm
by Weirdan
you have to set your session handler before you call session_start()

Posted: Tue Dec 19, 2006 7:07 pm
by Luke
:oops: unfamiliar with Zend_Session's inner workings. Thank you.

EDIT: Although I'm still pretty sure that set_session_save_handler works without having to change anything in php.ini, but I could be wrong.