4

I am sometime experiencing the following issue with CodeIgniter:

ERROR - 2019-03-05 19:57:26 --> Severity: Warning --> session_start(): Failed to decode session object. Session has been destroyed /system/libraries/Session/Session.php 143

This error appears in my server log and is impossible to artificialy replicate.

I already read the following SO questions:

I also asked on the CodeIgniter forum, but I didn't have any answer.

https://forum.codeigniter.com/thread-72960.html

Here are my session configuration (in application/config/config.php)

$config['sess_driver'] = 'files';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
$config['sess_save_path'] = NULL;
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE;

Any ideas what could be the roots of that problem and/or where to start ?

Fifi
  • 3,360
  • 2
  • 27
  • 53
  • Are sessions getting stored in the DB or the standard way? You should be able to set this in the Codigniter config file. – Daniel G Mar 08 '19 at 20:46
  • Have you seen this one? https://stackoverflow.com/questions/34944892/session-destroyed-out-of-nowhere-in-php – Bryan Mar 08 '19 at 22:24
  • Yes, I already read this question, but answers didn't help me so much. For the DB storage, I guess the session is stored in a file ( $config['sess_driver'] = 'files'; ) – Fifi Mar 09 '19 at 03:10

3 Answers3

16

I encountered this error when using the database option to store session information. When using this option, CodeIgniter stores session data in a table called ci_sessions, specifically in the 'data' column. By default, CodeIgniter creates this column as a blob datatype which has a maximum data size of 65,535 bytes. My application was exceeding that size and throwing the error. To remedy the issue, I changed the datatype to mediumblob which has a maximum size of 16,777,215 bytes. Afterwards, my application no longer generated the error and worked as expected.

Dave
  • 161
  • 1
  • 2
5

The problem is with this setting

$config['sess_save_path'] = NULL;

When using the "files" driver, which you are, as determined by the following

$config['sess_driver'] = 'files';

$config['sess_save_path'] must be set to the absolute path where the session files will be stored. e.g.

$config['sess_save_path'] = '/var/www/project/sessions/';

When set to NULL all kinds of weird and unpredictable things happen. The folder must also have appropriate ownership and permissions.

DFriend
  • 8,869
  • 1
  • 13
  • 26
3

In application/config/config.php, set this value:

$config['sess_save_path'] = sys_get_temp_dir();
Fifi
  • 3,360
  • 2
  • 27
  • 53