Sessiontoken - Are they supposed to keep growing?

Open to all! Ask other shopowners for help.
Post Reply
Moxamint
Member
Posts: 93
Joined: Fri Nov 06, 2020 10:36 am
Phoenix Version:
Has thanked: 33 times
Been thanked: 3 times

Sessiontoken - Are they supposed to keep growing?

Post by Moxamint »

Hi,

In my database, the number of sessiontokens keeps growing (four times the size of the rest of the data) and don't seem to expire/disappear. How do I keep them to a minimum/reasonable size? I'm on v1.0.8.20.

Thanks, Eddy


Join The Code Co-op to get access to your library in the Code Co-op Forum
heatherbell
Senior Contributor
Posts: 2540
Joined: Mon Oct 07, 2019 4:39 am
Phoenix Version:
Has thanked: 35 times
Been thanked: 243 times

Re: Sessiontoken - Are they supposed to keep growing?

Post by heatherbell »

Moxamint wrote: Sun Feb 26, 2023 1:06 am In my database, the number of sessiontokens keeps growing and don't seem to expire/disappear. How do I keep them to a minimum/reasonable size? I'm on v1.0.8.20.
Hoping that it helps, after researching your question, the best explanation I have found is on this thread link here:
https://www.oscommerce.com/forums/topic ... ions-table

If I understand correctly, it seems to be dependent on server PHP settings, e.g. we have no issues with old sessions being cleared automagically on any of our sites (running various versions from 1.0.5.0 to 1.0.8.20).
Guessing that is done in core here:
https://github.com/CE-PhoenixCart/Phoen ... hp#L23-L25

If you go down the route of a SQL query, when dealing with timestamps, a timestamp converter is useful, e.g. https://unixtime.org/
ecartz
Core Team
Posts: 3084
Joined: Tue Nov 05, 2019 6:02 pm
Phoenix Version:
Has thanked: 4 times
Been thanked: 208 times

Re: Sessiontoken - Are they supposed to keep growing?

Post by ecartz »

heatherbell wrote: Sun Feb 26, 2023 6:45 am If you go down the route of a SQL query, when dealing with timestamps, a timestamp converter is useful, e.g. https://unixtime.org/
It might be easier to just do what gc does:

Code: Select all

$GLOBALS['db']->query("DELETE FROM sessions WHERE expiry < '" . (int)strtotime('-1 week') . "'");
Add that (possibly via hook) to something in admin that you visit regularly but not frequently.

If you do it in phpMyAdmin, you can use UNIX_TIMESTAMP, e.g.

Code: Select all

DELETE FROM sessions WHERE expiry < UNIX_TIMESTAMP(NOW() - INTERVAL 1 WEEK)
But the easiest solution is to change session.gc_probability and session.gc_divisor to something like 1 and 100, e.g. in includes/configure.php

Code: Select all

ini_set('session.gc_probability', 1);
ini_set('session.gc_divisor', 100);
init_set('session.gc_max_lifetime', 604800);
Make the first number larger to make it happen more frequently. Make the second number larger to make it happen less frequently. Or vice versa for smaller. The first number should be smaller than the second number. The third number is the number of seconds since the session was last used to keep it. In this example, it will run 1/100 times and clear everything older than a week (seven days times 86,400 seconds in a day). I would not set the third number smaller than 1800 (half an hour) and would prefer at least 57,600 (sixteen hours). A week will make your sessions table a lot smaller and won't impact the typical user at all.

Most likely your php.ini file has either session.gc_probability or session.gc_max_lifetime set to 0, disabling the check.

https://www.php.net/manual/en/session.c ... robability


Join The Code Co-op to get access to your library in the Code Co-op Forum
Post Reply