• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Session garbage collection

#1
Hi,

While I have been using CI 3 for a few weeks now I have only just noticed that my sessions directory is not getting cleaned on my local machine. I have chosen to use the file driver and have set a directory in my root named sessions. The path is set in the config
PHP Code:
$config['sess_save_path'] = FCPATH.'sessions'

Sessions are created and data can be added, changed and deleted as normal. But it seems that the garbage collection is not working. Non of the old session files are being deleted.

Is this a know bug or am I missing something?
Reply

#2
PHP's garbage collection for sessions is controlled by session.gc_probability, session.gc_divisor, and session.gc_maxlifetime in php.ini. Generally, these can also be set in .htaccess, httpd.conf, via ini_set(), or, since PHP 5.3, in .user.ini.

However, many Linux configurations actually disable this by setting session.gc_probability to 0, then use a cron job or some other method to cleanup the default location for PHP sessions based on the session.gc_maxlifetime value. While this has the benefit of not triggering session cleanup specifically when a user visits the site, you would have to modify the existing cron job or create a new one to cleanup your session location, or use the default session location (generally stored in session.save_path).

If you use a session driver other than the file driver, it's a little more difficult to clean up the old sessions by doing anything other than setting the session.gc_* variables to reasonable values.
Reply

#3
(11-04-2015, 10:33 AM)mwhitney Wrote: PHP's garbage collection for sessions is controlled by session.gc_probability, session.gc_divisor, and session.gc_maxlifetime in php.ini. Generally, these can also be set in .htaccess, httpd.conf, via ini_set(), or, since PHP 5.3, in .user.ini.

However, many Linux configurations actually disable this by setting session.gc_probability to 0, then use a cron job or some other method to cleanup the default location for PHP sessions based on the session.gc_maxlifetime value. While this has the benefit of not triggering session cleanup specifically when a user visits the site, you would have to modify the existing cron job or create a new one to cleanup your session location, or use the default session location (generally stored in session.save_path).

If you use a session driver other than the file driver, it's a little more difficult to clean up the old sessions by doing anything other than setting the session.gc_* variables to reasonable values.

Thanks for that!

So this could mean that my local machine is not collecting the garbage, but my hosting server could be doing it correctly.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.