21 return array_merge(parent::clientConfig(),[
'interval' => $this->interval]);
26 if(!$this->session->start){
27 $this->session->start = time();
28 $this->
journal(
'Session start from remote address ' . $this->
component(
'security')->remoteAddr);
30 $this->_lastAlive = $this->session->alive;
31 $this->session->alive = time();
37 public function register($name){
38 if(!in_array($name,$ping = $this->session->ping ?: [])) $ping[] = $name;
39 $this->session->ping = $ping;
48 (!$this->maxSessionTime || (time() - $this->session->start <= $this->maxSessionTime * 60)) &&
49 (!$this->maxInactiveTime || (time() - $this->session->alive <= $this->maxInactiveTime * 60))
51 if($ping = $this->session->ping)
foreach($ping as $name) $this->_fred->component($name)->ping();
56 $this->session->start =
false;
57 return $this->router->reverse($this->front->defaultControllerName);
64 if($filename = $this->journalFilename)
try{
65 return \Rsi\File::write($filename,date($this->journalFormat) .
": $message\n",0666,
true);
78 if($this->journalPath && ($force || !rand(0,$this->journalGarbageChance)))
try{
81 foreach((
new \GlobIterator($this->journalPath .
'*' . $this->journalExt)) as $filename => $file)
try{
101 public function journals($filter = null,$order = null){
103 if($this->journalPath){
105 foreach((
new \GlobIterator($this->journalPath .
'*' . $this->journalExt)) as $filename => $file)
106 if(!$filter || (stripos(\
Rsi\File::read($filename),$filter) !==
false))
107 $journals[] = [
'name' => $file->getFilename(),
'time' => $file->getMTime(),
'size' => $file->getSize()];
108 if($order && $journals && array_key_exists($order,$journals[0]))
109 usort($journals,
function($a,$b) use ($order){
return strnatcmp($a[$order],$b[$order]); });
119 return $this->journalPath && !preg_match(
'/(\\/|\\\\|\\.\\.)/',$name) && \Rsi\Str::endsWith($name,$this->journalExt)
120 ? explode(
"\n",trim(\
Rsi\File::read($this->journalPath . $name)))
125 $interval = ini_get(
'session.gc_maxlifetime') / 90;
126 if($this->maxSessionTime) $interval = min($interval,$this->maxSessionTime / 10);
127 if($this->maxInactiveTime) $interval = min($interval,$this->maxInactiveTime / 10);
128 return max(1,$interval);
132 if(!$this->journalPath)
return false;
133 if(!$this->_journalFilename) $this->_journalFilename = $this->journalPath . session_id() .
$this->journalExt;
ping()
Ping the session to see its status.
$maxInactiveTime
Maximum period of inactivity (minutes; empty = infinite).
journal($message)
Add a message to the journal.
$journalTimout
Max idle time in seconds.
journals($filter=null, $order=null)
List all active journals.
$journalPath
Path for journal files (empty = do not save).
journalGarbage($force=false)
Clean-up the journals.
$maxSessionTime
Maximum duration of a session (minutes; empty = infinite).
$journalMaxSize
Max filesize in bytes.
journalMessages($name)
All messages from a journal.
component($name)
Get a component (local or default).