Jump to content

Session Handler Database - do not delete old sessions


horst
 Share

Recommended Posts

Hi, I'm using the Database Session Handler the first time with a site and have noticed that the no more used sessions get not deleted automatically. They get deleted when I'm logged in and go to Setup -> Sessions.

Is this normal behave or is there something wrong with the server the site is running on.

How is the deletion triggert? Can I do something together with lazy-cron?

Link to comment
Share on other sites

I believe in one of the posts about session files not getting deleted Ryan mentioned that the database session handler also relies on the native PHP garbage collection. On some Ubuntu servers, with default settings php gc does not run. Maybe you're on a ubuntu server as well?

http://processwire.com/talk/topic/5787-sessions-thousands-of-them/?fromsearch=1

  • Like 2
Link to comment
Share on other sites

@SiNNuT: thanks, yes it's Ubuntu. I will try that fix first with:

ini_set("session.gc_probability", 1);
ini_set("session.gc_divisor", 100);

And if this doesn't do it, I will delegate it to a cron-job.

  • Like 2
Link to comment
Share on other sites

Let me know you that goes for you, because i am just in the middle of these issues on a Ubuntu server myself and by the looks of it setting these options in config.php does not seem to work but i'll give it a couple of days more.

Link to comment
Share on other sites

Ok, I try out a few days and come back here.

(actually it looks promising, I have 5k+ sessions and the oldest one was created 24 hours and 10 minutes ago)

EDIT:

Now, almost 2 hours later, I have 200 records less. Oldest entry is 23 hours and 30 minutes ago.

Server-Engine: Apache 2.0 Handler - PHP 5.4.24-nmm1
Linux dd13102 3.2.0-57-generic #87-Ubuntu SMP Tue Nov 12 21:35:10 UTC 2013 x86_64
Edited by horst
Link to comment
Share on other sites

  • 5 years later...

Whoa, just got bit by this as well. Couple of my sites (on an Ubuntu server) were using SessionHandlerDB, so this happened:

> select count(*) from sessions;
+----------+
| count(*) |
+----------+
|  1561416 |
+----------+

1.5 million rows in the sessions table – "whoops". Should probably add sensible session.gc_probability number for these sites ?

  • Like 2
Link to comment
Share on other sites

  • 1 year later...

Sorry to ressurect this old topic. But I've got the same problem.

For now I am fine going to Setup -> Sessions as @horst suggested in his original post. But it doesn't seem to work. I visit this page, but sessions do not get deleted (as I can see in PhpMyAdmin). There is no button to clear old sessions either. Is it some bug on my side, or the sessions are not supposed to get deleted in this case?

 

Link to comment
Share on other sites

Just chiming in - I don't have a solution in terms of why the sessions are not clearing when you visit the Setup -> Sessions, but for me, going to Setup -> Sessions does clear the old sessions.

The first time I realized this was an issue was seeing the number of records in the sessions table; once i cleared those, the database shed something like 50-100MB. I also read some of the other solution (involving the ini_set) and this didn't work  - it seemed to make the site basically tank, and run really slow.

... and i guess my point was that this sessions not clearing in the DB is still an open issue, at this time..

  • Like 2
Link to comment
Share on other sites

  • 10 months later...

Just got bit by this as well... I realized that there was a massive increase in db rows (from 11k to 19k) so I checked the DB and saw the big sessions table. Found this thread, visited admin > access > session-db and boom - shrink from 19k to 8k rows:

qDKu6Pz.png

What are you guys doing about this? I'm also on ubuntu and have to update several installations I guess... What settings do you use?

Wouldn't it be the best if ProcessWire did automatically clear up old sessions on its own independently from the server config?

  • Like 2
Link to comment
Share on other sites

1 hour ago, Ivan Gretsky said:

Got same problem

1 hour ago, Ivan Gretsky said:

Had same thing with files

 

This should work for both, files and DB:

On 3/11/2014 at 12:09 AM, horst said:
ini_set("session.gc_probability", 1);
ini_set("session.gc_divisor", 100);

 

Link to comment
Share on other sites

  • 1 year later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...