Codeigniter frequent session expiration FIX

Well I have been using codeigniter for like 4 years now, and using it in my recent project. I discovered that for a large scale, cluster server application session will not work. I knew codeigniter has a feature to save sessions in database and so I did.

A new problem began to show up, they all had frequent session loss while submitting important data or browsing. The problem was that when the session cookie was updated, the session in the database was not.

Whenever a session cookie is updated codeigniter checks for the session saved in database, if they don't match, session is expired.

Solution:

Look at your config file.

$config['sess_cookie_name']     = 'ci_session_cookie';
$config['sess_expiration']      = 3600;
$config['sess_expire_on_close'] = FALSE;
$config['sess_encrypt_cookie']  = TRUE;
$config['sess_use_database']    = TRUE;
$config['sess_table_name'] = 'ci_sessions';
$config['sess_match_ip']        = FALSE;
$config['sess_match_useragent'] = TRUE;
$config['sess_time_to_update']  = 300;

you need to change the value for

$config['sess_time_to_update']

make it something equal to

$config['sess_expiration'];
$config['sess_time_to_update'] = 3600;

So that codeigniter does not check for session frequently.

Problem Solved.