Jump to content

Session cleaning


apeisa
 Share

Recommended Posts

How does pw cleans session files or does it at all?

I found out that I had few hundred megabytes of session files at /site/assets/sessions/ and oldest ones were from the day the site was build.

Should I build custom session cleaning, is this a bug or am I maybe using sessions wrong?

Link to comment
Share on other sites

Both versions just uses PHP's session functions, so ProcessWire isn't involved in the clearing of the session files. PHP's garbage collection should take care of them. But it sounds like it's not? I'll check around on some of my sites to see if the same thing is happening there. 

Link to comment
Share on other sites

Tested on a couple of sites here and PHP's garbage collector seems to be doing it's job. I don't have any session files older than 24 hours. If it helps, I've attached a screenshot from the phpinfo() session section on one of those sites. It might be good to compare to yours and see what's different. I'm guessing it's something in the garbage collection (gc_) options. Please let me know what you find. We can always override PHP's values for these (currently we don't override the gc_ options).  

post-1-13261427847_thumb.png

Link to comment
Share on other sites

Thanks Ryan.

I compared the settings and there are few differences:

Registered save handlers = files user

Registered serializer handlers = php php_binary wddx

session.bug_compat_42 = Off

session.bug_compat_warn = Off

session.gc_divisor = 1000

session.hash_bits_per_character = 5

session.save_path = /var/lib/php5

session.use_only_cookies = On

Link to comment
Share on other sites

The gc_divisor is one potential issue, though I don't think it would account for it entirely. But here's what php.net has to say about it:

session.gc_divisor coupled with session.gc_probability defines the probability that the gc (garbage collection) process is started on every session initialization. The probability is calculated by using gc_probability/gc_divisor, e.g. 1/100 means there is a 1% chance that the GC process starts on each request. session.gc_divisor defaults to 100.

So in your case with a gc_divisor of 1000 there is significantly less chance that the garbage collection will run... perhaps such a small chance that it almost never happens. Though I've not experimented with this setting, so can't say for sure.

Here's another thing I found:

Note: If you are using the default file-based session handler, your filesystem must keep track of access times (atime). Windows FAT does not so you will have to come up with another way to handle garbage collecting your session if you are stuck with a FAT filesystem or any other filesystem where atime tracking is not available. Since PHP 4.2.3 it has used mtime (modified date) instead of atime. So, you won't have problems with filesystems where atime tracking is not available.

If I'm reading this right, we don't have to be concerned about this issue. But it seems a bit strange they way they mentioned "Oh by the way, Since PHP 4.2.3...", as a side note at the end, so I'm a little suspicious of this. Is your file system fat?

Link to comment
Share on other sites

I found this in Drupal 7's source:

/**
* Some distributions of Linux (most notably Debian) ship their PHP
* installations with garbage collection (gc) disabled. Since Drupal depends on
* PHP's garbage collection for clearing sessions, ensure that garbage
* collection occurs by using the most common settings.
*/
ini_set('session.gc_probability', 1);
ini_set('session.gc_divisor', 100);

I'm thinking perhaps we should add the same to PW's default config file.

Link to comment
Share on other sites

Thanks Ryan. That probably is it, since we use Ubuntu (debian).

Strange thing is that garbage collection seems to work now on one site. We manually removed most of the files about week ago, but now oldest ones are little bit over 24 hours ago... But others are not working... so maybe there is that probability at work.

I'll follow how this progress few days without adding those lines, and will add those later to see better picture of what is going on.

Link to comment
Share on other sites

  • 1 month later...

I could be wrong, but I think your session.gc_probability being set to "0" means that the session garbage collection will never run. This should probably be changed to 1 (the default for PHP). But as previously noted, Drupal sets both gc_probability and gc_divisor, so I've been wondering if PW should too.

Link to comment
Share on other sites

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...