CodeIgniter Forums
Sessions still written to filesystem with database driver - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Sessions still written to filesystem with database driver (/showthread.php?tid=64589)



Sessions still written to filesystem with database driver - jhuet - 03-08-2016

Hello there,

Finally switch from CI2 to CI3 but i'm now having a strange behaviour on CI3. Despite using the database driver, sessions are stored both in files and in the database.

It seems that because of this, file storage is conflicting with other applications on the server already using this same directory to store file sessions thus resulting into "random" fatal errors : session_start(): Failed to initialize storage module: user (path: /var/lib/php5/sessions)

Is there any reason why sessions are stored in both ? Here's my configuration regarding sessions :

  'sess_driver' => 'database',
  'sess_cookie_name' => 'xxxxx',
  'sess_expiration' => 10800,
  'sess_save_path' => 'users_sessions_ci3',
  'sess_match_ip' => false,
  'sess_time_to_update' => 40,
  'sess_regenerate_destroy' => false,

Thanks in advance for your help.


RE: Sessions still written to filesystem with database driver - keulu - 03-08-2016

look for your php.ini config

try to comment "session.save_path" => ;session.save_path

and put

session.auto_start to 0

Edit :
and don't forget to restart php service


RE: Sessions still written to filesystem with database driver - jhuet - 03-08-2016

Thank you for your quick answer keulu. Unfortunatly, the php.ini already looks like this. I also made sure by checking with phpinfo();


RE: Sessions still written to filesystem with database driver - Narf - 03-08-2016

Nothing's written to the file-system when you use the database driver.

"/var/lib/php5/sessions" is only present in the error message because CI doesn't need to set the session.save_path INI when using a database, leaving the PHP engine "in the dark" when it comes to reporting these errors.

The error means that you don't have a default database configured or that an attempt to connect to it has failed.


RE: Sessions still written to filesystem with database driver - jhuet - 03-09-2016

Hey Narf, thanks for your clarification. I'll look into that direction but it's weird that sometimes it manages to connect to the database and sometimes it doesnt.

Anyway the /var/lib/php5/sessions directory is now full of session files and considering the quantity of them it's hard not to assume it's coming from this change. Most of them are at 0 byte though except the ones from PHPMyAdmin (i can tell because of their content). Actually, it looks like i'm getting these session_start errors when i'm also connected to PMA which uses files session. After some debugging i for sure never get into the files driver but always in the database one as expected.

I'd gladly take more inputs if anyone has any.


RE: Sessions still written to filesystem with database driver - jhuet - 03-09-2016

I also noticed that some session files are created by root user (others are apache's). It turns out that these are created at the same time cronjobs are runned by root user using CLI commands. Shouldn't CLI calls not create session files in any case ?


RE: Sessions still written to filesystem with database driver - Narf - 03-09-2016

CI_Session doesn't call session_start() under CLI, something else is doing it.


RE: Sessions still written to filesystem with database driver - jhuet - 03-09-2016

Alright, there seem to be a lot of things mixed up on our side that made the constations of the problem nebulous. It looks like we had other applications than PMA creating these empty session files and, as Narf told us, we got confused with the error displaying something about /var/lib/php5/sessions while in the end it was accesses to the database that were problematic.

I would have another question though that i can't find an answer for concerning the database driver. I understand the requirement for a non-persistent connection but why the need to use the 'default' $this->db one ? Would there be a problem using the 'default' connection as persistent and create another specific connection just for session handling that would be non-persistent ?

In any case, thanks for you help !


RE: Sessions still written to filesystem with database driver - Narf - 03-09-2016

There's no easy and/or reliable way to configure it to use a different connection.