CodeIgniter Forums
Why does my session table have 40 million records? - 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: Why does my session table have 40 million records? (/showthread.php?tid=71259)



Why does my session table have 40 million records? - sneakyimp - 07-23-2018

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`



RE: Why does my session table have 40 million records? - php_rocs - 07-23-2018

@sneakyimp

Are you following all the requirements mentioned in the documentation ( https://codeigniter.com/user_guide/libraries/sessions.html?highlight=session#database-driver )?


RE: Why does my session table have 40 million records? - sneakyimp - 07-23-2018

(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/libraries/sessions.html?highlight=session#database-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.


RE: Why does my session table have 40 million records? - dave friend - 07-23-2018

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".


RE: Why does my session table have 40 million records? - sneakyimp - 07-23-2018

(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.


RE: Why does my session table have 40 million records? - Pertti - 07-24-2018

(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.