Skip to content

Commit 3862948

Browse files
committed
🔨 rename Session class to Prune to depict exact functionality of the class
Signed-off-by: otengkwame <developerkwame@gmail.com>
1 parent 5d5f6fb commit 3862948

1 file changed

Lines changed: 68 additions & 0 deletions

File tree

Core/core/Session/Prune.php

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?php
2+
3+
/**
4+
* Clean Expired Sessions for Webby
5+
*
6+
* @author Kwame Oteng Appiah-Nti (Developer Kwame)
7+
*
8+
*/
9+
10+
namespace Base\Session;
11+
12+
13+
class Prune
14+
{
15+
/**
16+
* Force cleanup expired sessions
17+
* This happens when using session from database
18+
*/
19+
public function databaseSessions()
20+
{
21+
if (config_item('sess_driver') != 'database') {
22+
return;
23+
}
24+
25+
$expire = (time() - config_item('sess_expiration'));
26+
27+
get_instance()->load->database();
28+
get_instance()->db->where("timestamp < {$expire}");
29+
$delete = get_instance()->db->delete(config_item('sess_save_path'));
30+
31+
log_message('debug', 'Session garbage collection performed on database.');
32+
33+
return ($delete) ? true : false;
34+
}
35+
36+
/**
37+
* Force cleanup expired sessions
38+
* This happens when using session from files
39+
*/
40+
public function fileSessions()
41+
{
42+
43+
$sessionPath = SESSION_SAVE_PATH . DS;
44+
45+
$handle = opendir($sessionPath);
46+
47+
while (($file = readdir($handle)) !== false) {
48+
//Leave the directory protection alone
49+
if ($file == '.htaccess' || $file == 'index.html') {
50+
continue;
51+
}
52+
53+
$lastmodified = filemtime($sessionPath . $file);
54+
55+
//24 hours in a day * 3600 seconds per hour
56+
if ((time() - $lastmodified) > config_item('sess_expiration')) {
57+
@unlink($sessionPath . $file);
58+
}
59+
}
60+
61+
closedir($handle);
62+
63+
log_message('debug', 'Session garbage collection performed on files.');
64+
65+
return true;
66+
}
67+
}
68+
/* end of file ./engine/Core/Session/Session.php */

0 commit comments

Comments
 (0)