Po waszych radach i testach doszedłem do wniosku że pliki nie są takei fajne. Poza tym baza jest o niebo szybsza. Moje zmagania niech będą zatem przestrogą dla innych

Nowy kod. Jeszcze raz prosze o sugestie
<?php
class Main_Session extends Main_Object
{
private $data = array(); //data storage private $sessionId = 0;
private $sessionName = 'edicoSession';
public function __construct()
{
parent__construct();
$this->dbTable = $this->settings->dbPrefix . 'edc_session_main';
$this->_start();
//testing run of the session...
$this->data['run'] = $this->data['run'] + 1;
} else {
$this->data['run'] = 0;
$this->data['sessionCookie'] = $this->sessionId;
$this->data['browser'] = $_SERVER['HTTP_USER_AGENT'];
$this->startIp = $_SERVER['REMOTE_ADDR'];
$this->_cleanDatabase();
}
}
public function install()
{
$query = "DROP TABLE IF EXISTS $this->dbTable";
$this->dbDriver->query($query);
$query = "CREATE TABLE $this->dbTable (
`id` VARCHAR(64) NOT NULL, PRIMARY KEY(`id`),
`last_update` DATETIME, INDEX (`last_update`),
`data` TEXT
) ENGINE=InnoDB CHARACTER SET `utf8`;";
$this->dbDriver->query($query);
}
public function __destruct()
{
$this->_save($this->sessionId);
}
public function __get($aKey)
{
//handeling magic get method...
if (isset($this->data[$aKey])) { return $this->data[$aKey];
}
}
private function __set($aKey, $aValue)
{
//handeling magic set method...
$this->data[$aKey] = $aValue;
}
private function _start()
{
if ($_COOKIE[$this->sessionName] == '') {
//create new session and sessionId...
$this->sessionId = encrypt
(time()*rand(0
,999999
)).random_string
(6
); setcookie($this->sessionName, $this->sessionId); } else {
//load existing session file to use by this session...
$data = $this->_load($_COOKIE[$this->sessionName]);
if ($data['browser'] == $_SERVER['HTTP_USER_AGENT']) {
//use existing cookie as sessionId...
$this->sessionId = $_COOKIE[$this->sessionName];
$this->data = $data;
} else {
//cookie could have been stolen; start new session...
$this->sessionId = encrypt
(time(0
,999999
)*rand()).random_string
(6
); setcookie($this->sessionName, $this->sessionId); }
}
$this->log->addEntry(_SYSTEM_LOG_USER_SESSION_STARTED_IN_FOLDER_, $this->folder, NOTE);
}
private function _cleanDatabase()
{
$this->dbDriver->query(
"DELETE FROM $this->dbTable WHERE `last_update` <= NOW() - INTERVAL 15 MINUTE"
);
}
private function _load($aSessionId)
{
$this->dbDriver->query(
"SELECT * FROM $this->dbTable WHERE `id` = '$aSessionId'"
);
$row = $this->dbDriver->fetchRow();
}
private function _save($aSessionId)
{
$this->dbDriver->query(
"INSERT INTO $this->dbTable SET
`id` = '$aSessionId',
`last_update` = NOW()
ON DUPLICATE KEY UPDATE
`last_update` = NOW()"
);
}
}
?>