<?php
class SessionHandle
{
public function open($savePath,$sessionName)
{
echo 'This is open </br>';
return true;
}
public function close()
{
echo 'This is close </br>';
return true;
}
public function read($id)
{
echo 'This is read </br>';
echo $id;
return 'sssxx';
}
public function write($id, $data)
{
echo 'This is write </br>';
echo $id;
var_dump('expression');
echo $data;
return true;
}
public function destroy($id)
{
echo 'This is des </br>';
return true;
}
public function gc($maxLifetime)
{
echo 'This is gc </br>';
//echo $maxLifetime;
return false;
}
}
ini_set('session.gc_probability',1);
ini_set('session.gc_divisor',100);
$session = new SessionHandle();
@session_set_save_handler(
array(&$session, "open"),
array(&$session, "close"),
array(&$session, "read"),
array(&$session, "write"),
array(&$session, "destroy"),
array(&$session, "gc")
);
session_start();
$_SESSION['views']=1;
var_dump($_SESSION['views'] . 'abc');
总结:PHP session 每次request结束之后会把所有的session重新更新一遍。Session 每次都是先读取后存储!用户关闭浏览器并不会触发gc的执行,只会销毁没有指定保存时长的cookie。