Jump to content
horst

Session Handler Database - do not delete old sessions

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?

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
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.

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

High five, putting those settings in config.php seems to have solved it for me as well.

  • Like 2

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Peter Knight
      How do you guys handle large session tables when sessions are being recorded to the database?
      I notice one of my sites has a session table of over 14MB 
      Am I missing a way in the Admin or a module to auto-remove any sessions older than X days?
      Thanks
       
    • By helmut2509
      In my PW-Application there is currently no session timeout.
      I want to set the user session to 60 minutes which means that after 60 minutes of inactivity the user will be redirected to the homepage.
      so I added the following entry to my config.php:
      $config->sessionExpireSeconds = 120; (120 seconds is just for testing).
      But after five minutes of inactivity I am still logged in, there is no redirection.
      Is there anything wrong or did I miss something?
      In php.ini I have the entry:
      session.cookie_lifetime = 3600
    • By DooM
      Hello guys,
      I'm trying to figure out how to sync fields and templates between staging and production environments.
      I've found Migrations module by Lostkobrakai, but with use of it all the fields and templates must be created by API, which is kind of uncomfortable.
      I also tried ProcessDatabaseBackups module which can export only certain tables, but I don't think it's the best practice to do that.
      How do you guys solve this problem? It's very annoying to setup everything three times (dev, staging, production).
      Thanks a lot :)
    • By iipa
      Hi everybody!
      I have been reading about Multisite, but it kinda bugs me that every topic talks about having both admin and database same for multiple sites.
      I have a project where customer tests it by adding content to the site, while I still need to do some changes here and there in code, maybe some in database. If something crashes for a while, customer can't keep testing, which is a bit problematic.
      Is there any way that I could have two separate versions of one site ("production" and development) that share the same database, but are otherwise independent? Just the thought of having to migrate database every time I want to show client something new gives me anxiety 😁
    • By celfred
      Hello,
      I'm facing a weird issue here. I have a page loaded with this code inside (my comments in line ends) :

      if ($session->allPlayers) { // Set in a head.inc file. I have also a $session->set('allTeams', $allTeams); in my head.inc   $allPlayers = $session->allPlayers; } else {   $allPlayers = getAllPlayers($user, false);   $session->set('allPlayers', $allPlayers); } bd($session->getAll()); // HERE, I get a number of 11 variables which is what I expect In the same page, I have a link pointing to ajaxContent.php that loads stuff via Ajax.
      I just write this in my ajaxContent.php to test :

      bd($session->getAll()); // HERE, I get only 9 variables. All my newly set $session variables ($allTeams and $allPlayers) are not conveyed to ajaxContent.php ??? Would you have any idea why is that ??? Another thing : I have a $session->headMenu set in my head.inc, and this one works fine. I can retrieve it in my ajaxContent.php page.
      I've tried cleaning all caches but it doesn't change anything 😞 
      At first, I expected it to be a 15-minute update to my site... It turns out to be a 2-hour issue and I'm still  stuck.
      Thanks for your ideas ! 
×
×
  • Create New...