CodeIgniter icon indicating copy to clipboard operation
CodeIgniter copied to clipboard

Getting session data error in log after codeigniter 3.1.3 update

Open JoonasC opened this issue 9 years ago • 5 comments

So, i've been having a problem, where sometimes my sessions randomly timeout even though the timeout is 30 minutes. I've checked the logs and been seeing this: ERROR - 2017-01-28 02:27:54 --> Severity: Warning --> Unknown: Failed to write session data (user). Please verify that the current setting of session.save_path is correct (ci_sessions) Unknown 0. So at first i thought there might be something wrong with my db setup. So i deleted my existing ci_sessions table, went to your website and copied the current query for creating tables for mysql: https://www.codeigniter.com/user_guide/libraries/sessions.html#database-driver. But i'm still getting this error. And it appears to be happening at random, plus i can see stored sessions in the db, which means it's still working most of the time... My config.php:

$config['sess_driver'] = 'database';
$config['sess_cookie_name'] = 'dyn_s_check';
$config['sess_expiration'] = 1800;
$config['sess_save_path'] = 'ci_sessions';
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = TRUE;

My database.php:

$active_group = 'default';
$query_builder = true;

//Db for Localhost
$db['default'] = array(
    'dsn'    => '',
    'hostname' => 'localhost',
    'username' => 'root',
    'password' => '',
    'database' => 'dynavio',
    'dbdriver' => 'mysqli',
    'dbprefix' => '',
    'pconnect' => false,
    'db_debug' => (ENVIRONMENT !== 'production'),
    'cache_on' => false,
    'cachedir' => '',
    'char_set' => 'utf8',
    'dbcollat' => 'utf8_unicode_ci',
    'swap_pre' => '',
    'encrypt' => false,
    'compress' => false,
    'stricton' => false,
    'failover' => array(),
    'save_queries' => true
);

JoonasC avatar Jan 28 '17 02:01 JoonasC

Actually, it looks like it happens everytime there's a session regeneration.

JoonasC avatar Jan 28 '17 04:01 JoonasC

Could it be because of the $config['sess_regenerate_destroy'] = TRUE;? I'm going to turn it off, just to see.

JoonasC avatar Jan 28 '17 04:01 JoonasC

Ok, it was because of that, nevermind.

JoonasC avatar Jan 28 '17 04:01 JoonasC

This is a bug tracker, not a support ticketing system ...

Just as you're not supposed to open issues for non-bugs, you're also not supposed to close them as soon as you find a work-around for yourself.

Luckily, someone else had previously reported this and it has been fixed already: 37226c036a52ae857b13109774b1cdfc4b1d4db9

narfbg avatar Jan 30 '17 08:01 narfbg

Just execute the one of the following SQL queries, depending on your database:

// MySQL: ALTER TABLE ci_sessions CHANGE id id varchar(128) NOT NULL;

// PostgreSQL ALTER TABLE ci_sessions ALTER COLUMN id SET DATA TYPE varchar(128);

https://www.codeigniter.com/userguide3/installation/upgrade_312.html

aleksandro1387 avatar Jun 04 '18 18:06 aleksandro1387