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

#1
Hi folks,

For some reason I have the impression that the garbage collection is not working as intended. These settings are used in CodeIgniter:
Code:
$config['sess_driver'] = 'database';
$config['sess_cookie_name'] = 'tb_sess';
$config['sess_expiration'] = 7200;
$config['sess_save_path'] = 'ci_sessions';
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE;

And these are set according to PHPInfo:
Code:
Directive Local Value Master Value
session.gc_divisor 1000 1000
session.gc_maxlifetime 1440 1440
session.gc_probability 1

When I look in the session table, there are over 10.000 rows. How come these are not yet removed by the garbage collection? I'm hoping someone could shed some light on what I am doing wrong.

Thanks in advance.

Reno
Reply

#2
You can edit php.ini an adjust either the session.gc_divisor or session.gc_probability to change the probability that GC will occur. Currently you're set to one chance in 1000 that GC will run when a session is initiated. GC can be time intensive so you don't want to run too often, particularly on a busy site.
Reply

#3
If you want you can set up a cron and do your own custom garbage collection based on your session settings. You don't have to rely on the built in GC mechanism. This is one example:

PHP Code:
public function ci_sessions_gc()
 
   {
 
       $this->load->database();
 
       
        $sess_expiration 
config_item('sess_expiration');
 
       $sess_save_path  config_item('sess_save_path');

 
       if$sess_expiration )
 
       {
 
           $epoch_expired time() - $sess_expiration;
 
           $this->db->where('timestamp <'$epoch_expired)
 
               ->delete$sess_save_path );
 
       }
 
   
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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