Welcome Guest, Not a member yet? Register   Sign In
Why does my session table have 40 million records?
#1

(This post was last modified: 07-23-2018, 06:06 PM by sneakyimp.)

I recently launched a site built on CodeIgniter. Today I learned that the session table has over 40 MILLION records in it. These are my session-related settings in the config file:
Code:
$config['sess_driver'] = 'database';
$config['sess_cookie_name'] = 'ci-session';
$config['sess_expiration'] = 7200;
$config['sess_save_path'] = 'ci_session';
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE;
The earliest session record dates from before our site launch and its ip corresponds to my ip address.

What's the issue here? It's my understanding that the CI Session class periodically garbage collects this table, but it does not appear to be working properly. This query says there are 549706 distinct ip addresses in that able:
Code:
SELECT COUNT(DISTINCT ip_address) FROM `ci_session`
Reply
#2

@sneakyimp

Are you following all the requirements mentioned in the documentation ( https://codeigniter.com/user_guide/libra...ase-driver )?
Reply
#3

(07-23-2018, 06:39 PM)php_rocs Wrote: @sneakyimp

Are you following all the requirements mentioned in the documentation ( https://codeigniter.com/user_guide/libra...ase-driver )?

Can you be more specific? The site has successfully handled sessions for a couple of months since launch, we just have too many records in the session table.
Reply
#4

What are the settings in php.ini for session.gc_probability and session.gc_divisor? If the first is 0 (zero) then that explains why no "garbage" ever gets "collected".
Reply
#5

(07-23-2018, 09:08 PM)dave friend Wrote: What are the settings in php.ini for session.gc_probability and session.gc_divisor? If the first is 0 (zero) then that explains why no "garbage" ever gets "collected".

Bingo! session.gc_probability was zero for some reason. I changed this value in the PHP.ini files and restarted apache and the new value has taken hold. I'll keep an eye on the table to make sure it gets emptied periodically. It's too bad there's no log where we can check if it is in fact being emptied.
Reply
#6

(07-23-2018, 05:35 PM)sneakyimp Wrote: session table has over 40 MILLION records in it

On a side not, pretty impressive if you didn't notice any site slowdown.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB