to work around the not terminated sessions (because php is configured by default only to check it on every 100th session-creation), we terminate now all timed out sessions when a list of sessions is requested

This commit is contained in:
Ralf Becker 2005-06-18 06:38:29 +00:00
parent 1a0f3ab29c
commit 332c9c41df

View File

@ -181,16 +181,17 @@
) * $sign; ) * $sign;
} }
/*! /**
@function list_sessions * get list of normal / non-anonymous sessions (works only for session.handler = files!, but that's the default)
@abstract get list of normal / non-anonymous sessions *
@note The data form the session-files get cached in the app_session phpgwapi/php4_session_cache * The data from the session-files get cached in the app_session phpgwapi/php4_session_cache
@author ralfbecker *
* @author RalfBecker-AT-outdoor-training.de
*/ */
function list_sessions($start,$order,$sort,$all_no_sort = False) function list_sessions($start,$order,$sort,$all_no_sort = False)
{ {
//echo "<p>session_php4::list_sessions($start,'$order','$sort',$all)</p>\n"; //echo "<p>session_php4::list_sessions($start,'$order','$sort',$all)</p>\n";
//$session_cache = $this->appsession('php4_session_cache','phpgwapi'); $session_cache = $this->appsession('php4_session_cache','phpgwapi');
$values = array(); $values = array();
$maxmatchs = $GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs']; $maxmatchs = $GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs'];
@ -199,19 +200,25 @@
{ {
return $values; return $values;
} }
while ($file = readdir($dir)) while (($file = readdir($dir)))
{ {
if (substr($file,0,5) != 'sess_' || $session_cache[$file] === false) if (substr($file,0,5) != 'sess_' || $session_cache[$file] === false)
{ {
continue; continue;
} }
if (isset($session_cache[$file]) && !$session_cache[$file]) // session is marked as not to list (not ours or anonymous)
{
continue;
}
if (isset($session_cache[$file])) // use copy from cache if (isset($session_cache[$file])) // use copy from cache
{ {
if (!$all_no_sort) // we need the up-to-date data --> unset and reread it $session = $session_cache[$file];
if (!$all_no_sort || // we need the up-to-date data --> unset and reread it
$session['session_dla'] <= (time() - $GLOBALS['egw_info']['server']['sessions_timeout'])) // cached dla is timeout
{ {
unset($session_cache[$file]); unset($session_cache[$file]);
} }
$session = $session_cache[$file];
} }
if (!isset($session_cache[$file])) // not in cache, read and cache it if (!isset($session_cache[$file])) // not in cache, read and cache it
{ {
@ -234,16 +241,25 @@
$session = unserialize(substr($session,1+strlen(EGW_SESSION_VAR))); $session = unserialize(substr($session,1+strlen(EGW_SESSION_VAR)));
unset($session['app_sessions']); // not needed, saves memory unset($session['app_sessions']); // not needed, saves memory
$session_cache[$file] = $session; $session_cache[$file] = $session;
}
if($session['session_flags'] == 'A' || !$session['session_id'] || if($session['session_flags'] == 'A' || !$session['session_id'] ||
$session['session_install_id'] != $GLOBALS['egw_info']['server']['install_id']) $session['session_install_id'] != $GLOBALS['egw_info']['server']['install_id'])
{ {
$session_cache[$file] = false; // dont try reading it again $session_cache[$file] = false; // dont try reading it again
continue; // no anonymous sessions or other domains or installations continue; // no anonymous sessions or other domains or installations
} }
//echo "file='$file'=<pre>"; print_r($session); echo "</pre>"; // check for and terminate sessions which are timed out ==> destroy them
// this should be not necessary if php is configured right, but I'm sick of the questions on the list
if ($session['session_dla'] <= (time() - $GLOBALS['egw_info']['server']['sessions_timeout']))
{
//echo "session $session[session_id] is timed out !!!<br>\n";
@unlink($path . '/' . $file);
$session_cache[$file] = false;
continue;
}
$session['php_session_file'] = $path . '/' . $file; $session['php_session_file'] = $path . '/' . $file;
}
//echo "file='$file'=<pre>"; print_r($session); echo "</pre>";
$values[$session['session_id']] = $session; $values[$session['session_id']] = $session;
} }
closedir($dir); closedir($dir);
@ -272,10 +288,10 @@
return $values; return $values;
} }
/*! /**
@function total * get number of normal / non-anonymous sessions
@abstract get number of normal / non-anonymous sessions *
@author ralfbecker * @author RalfBecker-AT-outdoor-training.de
*/ */
function total() function total()
{ {