<?php
/**
* writeSometimes
* a filter which reduces unnecessary writes
*/
class writeSometimes extends stackSess {
private $dataread;
function open($save_path, $name)
{
if ($this->shStackNext) {
return $this->shStackNext->open($save_path, $name);
} else {
trigger_error("writeSometimes session handler has no storage capability");
return false;
}
}
function read($session_id)
{
if ($this->shStackNext) {
$session_data=$this->shStackNext->read($session_id);
$this->dataread=sha1($session_id . $session_data);
return $session_data;
} else {
return '';
}
}
function write($session_id, $session_data)
{
if ($this->shStackNext) {
$data_to_write=sha1($session_id . $session_data);
if ($data_to_write!=$this->dataread) {
return $this->shStackNext->write($session_id, $session_data);
}
$age=time() - $this->shStackNext->lastAccessed();
$max=ini_get('session.gc_maxlifetime');
if ($age<$max && $age>0.7*$max) {
return $this->shStackNext->write($session_id, $session_data);
}
if ($age>$max) {
// session should have expired
return false;
}
// write is redundant
return true;
}
return false;
}
}
|