Jump to content

PHP5 Session error: "Failed to initialize storage module: user"


laidbackwebsage

Recommended Posts

Please confirm that the following overwrite the settings in my php.ini file:

 

ini_set('session.save_handler',   'user');                       // Tells PHP5 that I am using my own storage handling
ini_set('session.save_path',      '<My Database Name>');       // The name of the database I am storing the session data in,
                                                                                  // instead of the default file storage.
ini_set('session.name',           '<My Session Table Name>'); // The name of the database table I am storing the session data in
ini_set('session.gc_maxlifetime', 1800);                       // How long before the session will be garbage-collected
ini_set('session.use_cookies',    1);                            // Tells PHP5 to create a session cookie

 

(These are the session values from my php.ini file:

Directive Local Value Master Value

session.auto_start Off Off

session.bug_compat_42 On On

session.bug_compat_warn On On

session.cache_expire 180 180

session.cache_limiter nocache nocache

session.cookie_domain no value no value

session.cookie_httponly Off Off

session.cookie_lifetime 0 0

session.cookie_path / /

session.cookie_secure Off Off

session.entropy_file no value no value

session.entropy_length 0 0

session.gc_divisor 100 100

session.gc_maxlifetime 1440 1440

session.gc_probability 0 0

session.hash_bits_per_character 4 4

session.hash_function 0 0

session.name PHPSESSID PHPSESSID

session.referer_check no value no value

session.save_handler files files

session.save_path /tmp /tmp

session.serialize_handler php php

session.use_cookies On On

session.use_only_cookies Off Off

session.use_trans_sid 0 0

)

 

I have my own session handlers defined in a Sessions Class:

 

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

 

I have already tried changing the values directly in my php.ini file, but I get the same results, which are:

 

Fatal error: session_start() [<a href='function.session-start'>function.session-start</a>]: Failed to initialize storage module: user (path: <DB Name>) in /path/to/php/conf/file.php on line 61

 

(Line 61 is where I call "session_start()".)

 

I'm really pulling my hair out, so any help you can give me would be greatly appreciated.

 

Thanks!

 

Kevin J

The error indicates that either session_set_save_handler() was not called before the ini_set() statements or before the session start or your open or read class functions returned a false value or some other unexpected value.

 

Searching for that error indicates it most likely occurs when you set session.save_handler but no user handler has been registered yet using the session_set_save_handler() function call.

 

If your code executes the ini_set() statements before the session_start() or before a phpinfo() statement, then the settings will be in effect.

 

Unless your class code uses session.save_path to select the database name, there is no point it setting it.

 

session.name is the name that is used in the session cookie. Using it as the table name would work as long as you follow the naming restrictions mentioned in the php manual.

 

session.gc_maxlifetime is the age of the session data files/records that are deleted when GC runs. It is not "How long before" anything happens in the session.

 

If your phpinfo() statement is called after the ini_set() statements, the changes show up. If you made the changes in php.ini and they did not show up, either you did not stop and start the web server to get changes made to php.ini to take effect or the file you are making changes to is not the one php is reading.

 

Lastly, is there a real good reason why you are not using the built-in php files handler? Using parsed/interpreted php routines to perform the functions through session_set_save_handler() is at least 10 - 20 times slower then using the compiled code of the built-in file handler.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.