PHP 实现多服务器共享 SESSION 数据(4)
$rs->Close();
return $v;
} //end if
} //end if
return '';
} //end function
function write($sesskey, $data) {
global $MY_SESS_CONN;
$qkey = $MY_SESS_CONN->qstr($sesskey);
$expiry = time() + My_SESS_TIME; //设置过期时间
//写入 SESSION
$arr = array(
'sesskey' => $qkey,
'expiry' => $expiry,
'data' => $data);
$MY_SESS_CONN->Replace('sess', $arr, 'sesskey', $autoQuote = true);
return true;
} //end function
function destroy($sesskey) {
global $MY_SESS_CONN;
$sql = 'DELETE FROM sess WHERE sesskey=' . $MY_SESS_CONN->qstr($sesskey);
$rs =& $MY_SESS_CONN->Execute($sql);
return true;
} //end function
function gc($maxlifetime = null) {
global $MY_SESS_CONN;
$sql = 'DELETE FROM sess WHERE expiry<' . time();
$MY_SESS_CONN->Execute($sql);
//由于经常性的对表 sess 做删除操作,容易产生碎片,
//所以在垃圾回收中对该表进行优化操作。
$sql = 'OPTIMIZE TABLE sess';
$MY_SESS_CONN->Execute($sql);
return true;
} //end function
} ///:~
相关新闻>>
- 发表评论
-
- 最新评论 进入详细评论页>>