php.ini里面有英文的说明,不妨看看 ; Define the probability that the '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_probability = 1 session.gc_divisor = 100; After this number of seconds, stored data will be seen as 'garbage' and ; cleaned up by the garbage collection process. session.gc_maxlifetime = 1440
“为什么只置空DATA列,没有删除整条session记录?” 这是因为t1.php中只是 unset($_SESSION["user"]); 而不是session_destroy() 所以,session还是在工作状态,程序结束时php将调用sess_mysql_write函数去修改相应的内容。 对于你的示例,由于唯一的session变量user已被删除了,当然DATA列就是空的了。你多定义几个session变量就知道了“按照设置的超时才删除整条了记录。 当多个用户在线会发生这种情况:新登陆了一个用户,如果这时垃圾收集器启动,会删除前面的在线用户在数据库中SESSION的信息” 你的 function sess_mysql_gc($max_lifetime) { global $sess_mysql; $old=time()-$max_lifetime; $result=mysql_query("DELETE FROM ".$sess_mysql["table"]." WHERE UNIX_TIMESTAMP(t_stamp)<$'$old'") or die(mysql_error()); //if ($result) // echo "ok"; return true; } 函数有问题,通常参数$max_lifetime不能被正确传入。因此 $old=time()-$max_lifetime; 实际就是 $old=time(); 其实既然已经自己管理session了,那么也就没有必要借助“垃圾收集器”了 应该如手册中示例那样直接返回true function sess_mysql_gc($max_lifetime) { return true; } 而把清理过期的工作放到sess_mysql_open中完成 超时的时间自己定,不依赖php.ini中的设置
php手册上关于session_sat_save_handler是这样说的: /********************************************* * WARNING - You will need to implement some * * sort of garbage collection routine here. * *********************************************/ function gc($maxlifetime) { return true; }它提示需要自己实现垃圾收集器
; Define the probability that the '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_probability = 1
session.gc_divisor = 100; After this number of seconds, stored data will be seen as 'garbage' and
; cleaned up by the garbage collection process.
session.gc_maxlifetime = 1440
当多个用户在线会发生这种情况:新登陆了一个用户,如果这时垃圾收集器启动,会删除前面的在线用户在数据库中SESSION的信息
这是因为t1.php中只是
unset($_SESSION["user"]);
而不是session_destroy()
所以,session还是在工作状态,程序结束时php将调用sess_mysql_write函数去修改相应的内容。
对于你的示例,由于唯一的session变量user已被删除了,当然DATA列就是空的了。你多定义几个session变量就知道了“按照设置的超时才删除整条了记录。
当多个用户在线会发生这种情况:新登陆了一个用户,如果这时垃圾收集器启动,会删除前面的在线用户在数据库中SESSION的信息”
你的
function sess_mysql_gc($max_lifetime)
{
global $sess_mysql;
$old=time()-$max_lifetime;
$result=mysql_query("DELETE FROM ".$sess_mysql["table"]." WHERE UNIX_TIMESTAMP(t_stamp)<$'$old'") or die(mysql_error());
//if ($result)
// echo "ok";
return true;
}
函数有问题,通常参数$max_lifetime不能被正确传入。因此
$old=time()-$max_lifetime;
实际就是
$old=time();
其实既然已经自己管理session了,那么也就没有必要借助“垃圾收集器”了
应该如手册中示例那样直接返回true
function sess_mysql_gc($max_lifetime)
{
return true;
}
而把清理过期的工作放到sess_mysql_open中完成
超时的时间自己定,不依赖php.ini中的设置
/*********************************************
* WARNING - You will need to implement some *
* sort of garbage collection routine here. *
*********************************************/
function gc($maxlifetime)
{
return true;
}它提示需要自己实现垃圾收集器