Why would session_set_save_handler not work?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Why would session_set_save_handler not work?

Post 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?
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

AFAIK user-defined session handler has to be allowed explicitly in php.ini
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post 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... :?
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

this directive should include 'user' for custom session handlers to work
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post 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
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

you have to set your session handler before you call session_start()
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post 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.
Post Reply