xoops forums

sudhaker

Not too shy to talk
Posted on: 2003/11/18 19:44
sudhaker
sudhaker (Show more)
Not too shy to talk
Posts: 117
Since: 2003/2/6 2
#1

XoopsSessionHandler


Inside the method write() of class XoopsSessionHandler, a QUERY decides what to run next, INSERT or UPDATE. So there is always 2 SQL query per session write.

As INSERT will happen just once per session, so trying to UPDATE first and if it fails then doing INSERT can be more efficient way of handling the same.

This will save 1 SQL query for any further request.

I tried it on SQLite with this code, working fine.

$sql = sprintf("UPDATE %s SET sess_updated = %u, sess_data = '%s' WHERE sess_id = '%s'", 'session', time(), $sess_data, $sess_id);
//echo "Debug: $sql <br>";
sqlite_query($this->db, $sql);
if (sqlite_changes($this->db) != 1)
{
$sql = sprintf("INSERT INTO %s (sess_id, sess_updated, sess_ip, sess_data) VALUES ('%s', %u, '%s', '%s')", 'session', $sess_id, time(), $_SERVER['REMOTE_ADDR'], $sess_data);
//echo "Debug: $sql <br>";
sqlite_query($this->db, $sql);
}
return true;


---
Performance does matter...

sudhaker

Not too shy to talk
Posted on: 2003/11/30 6:58
sudhaker
sudhaker (Show more)
Not too shy to talk
Posts: 117
Since: 2003/2/6 2
#2

Re: XoopsSessionHandler

No one listening here...