Skip to content

Commit fac5e94

Browse files
committed
session gc
session gc
1 parent 74ad60d commit fac5e94

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

vitex/service/session/SessionDriverInterface.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,10 @@ public function set($key, $val, $expire = 60);
3636
* @return mixed
3737
*/
3838
public function delete($key);
39+
40+
/**
41+
* 回收文件
42+
* @return mixed
43+
*/
44+
public function gc($maxlifetime);
3945
}

vitex/service/session/SessionHandler.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public function destroy($session_id)
5151

5252
public function gc($maxlifetime)
5353
{
54+
$this->driver->gc($maxlifetime);
5455
return true;
5556
}
5657

vitex/service/session/drivers/FileDriver.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function __construct()
3030
$this->storePath = $vitex->getConfig('session.file.path');
3131
$this->lifetime = $vitex->getConfig('session.lifetime');
3232

33-
if(!$this->storePath){
33+
if (!$this->storePath) {
3434
$this->storePath = sys_get_temp_dir();
3535
}
3636
}
@@ -56,6 +56,17 @@ public function delete($key)
5656
unlink($this->storePath . '/' . $key);
5757
}
5858

59+
public function gc($maxlifetime)
60+
{
61+
file_put_contents("/home/www/gc.txt",1);
62+
$expireTime = time() - ($maxlifetime * 60);
63+
foreach (glob($this->storePath.'/*') as $file) {
64+
if (is_file($file) && filemtime($file) < $expireTime) {
65+
@unlink($file);
66+
}
67+
}
68+
}
69+
5970
/**
6071
* 加锁获取内容
6172
* @param $path

0 commit comments

Comments
 (0)