Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#1910 closed Bug (fixed)

Check session.gc_probability so tmp/sessions files don't grow out of control

Reported by: matt Owned by:
Priority: normal Milestone: Piwik 1.1
Component: Core Keywords:
Cc: Sensitive: no

Description

On the demo server, there are thousands of session files in tmp/sessions.

I also saw a tweet complaining about these: http://translate.googleusercontent.com/translate_c?hl=en&sl=auto&tl=en&u=http://twitter.com/gerritvanaaken/statuses/16796496468905984&rurl=translate.google.com&twu=1&usg=ALkJrhgTQd9DhFc-ekLd1yoPAtBVLTADDw

What is the solution to this problem, could we purge on a regular basis the out of date session files?

Change History (12)

comment:1 Changed 3 years ago by vipsoft (robocoder)

  • Resolution set to duplicate
  • Status changed from new to closed

Marking as dupe of #1279. When we move sessions to db, we'll have to implement our own session file cleanup.

Previously commented on in http://dev.piwik.org/trac/ticket/1279#comment:13

comment:2 Changed 3 years ago by matt (mattab)

  • Resolution duplicate deleted
  • Status changed from closed to reopened

I think we can run a manual cleanup function as a Piwik Scheduled task

Something like

$current_time = time();
$path = '/path/to/sessions/';

$handle = opendir($path);
while (($filename = readdir($handle)) !== false)
{
if ($filename != '.' && $filename != '..')
{
$filemtime = filemtime($path . $filename);
if ($current_time - $filemtime > 3600) {unlink($path . $filename);}
}
}

comment:3 Changed 3 years ago by vipsoft (robocoder)

(In [3514]) refs #1279, refs #1910 - language preference for anonymous users is now stored in a cookie; we can't use this workaround for the dashboard layout because of cookie size limits

comment:4 Changed 3 years ago by vipsoft (robocoder)

(In [3515]) refs #1279, refs #1910 - fix typo

comment:5 Changed 3 years ago by vipsoft (robocoder)

(In [3548]) refs #1910 - set expiry on anonymous user dashboard layouts

comment:6 Changed 3 years ago by vipsoft (robocoder)

matt: on demo.piwik.org, session.gc_probability = 0 ... which means garbage collection never runs. AFAIK this is a web server configuration error.

comment:7 Changed 3 years ago by vipsoft (robocoder)

looking at gerritvanaaken's tweet, the ftp user ID can't access the tmp files created under the web server user ID (which is an expected permission issue).

comment:8 Changed 3 years ago by vipsoft (robocoder)

  • Milestone changed from 1.1 - Piwik 1.1 to 1.2 - Piwik 1.2
  • Priority changed from major to normal
  • Summary changed from tmp/sessions files grow out of control to Installation: check session.gc_probability/gc_divisor so tmp/sessions files don't grow out of control

comment:9 Changed 3 years ago by matt (mattab)

  • Milestone changed from 1.2 - Piwik 1.2 to 1.x - Piwik 1.x

I wonder if it would

  • work at all to call ini_set( session.gc_probability ) and set it to non zero value
  • when we detect that this is zero
  • and if this is desired to interact with server configuration
  • and if PHP will apply the garbage collection to the current customized session path (ie tmp/sessions)

Requires experimentation

comment:10 Changed 3 years ago by vipsoft (robocoder)

  • Milestone changed from 1.x - Piwik 1.x to 1.1 - Piwik 1.1
  • Summary changed from Installation: check session.gc_probability/gc_divisor so tmp/sessions files don't grow out of control to Check session.gc_probability/gc_divisor so tmp/sessions files don't grow out of control

Judging from the comments in php.ini, I think the behaviour on the demo was Debian-specific. In a standard PHP build, if session.gc_probability is undefined, it defaults to 1.

Looking at the PHP source, garbage collection is triggered at the end of session_start().

So, I'll set session.gc_probability to 1 if zero, and we're using a local session folder.

comment:11 Changed 3 years ago by vipsoft (robocoder)

  • Resolution set to fixed
  • Status changed from reopened to closed

(In [3552]) fixes #1910

comment:12 Changed 3 years ago by vipsoft (robocoder)

  • Summary changed from Check session.gc_probability/gc_divisor so tmp/sessions files don't grow out of control to Check session.gc_probability so tmp/sessions files don't grow out of control
Note: See TracTickets for help on using tickets.