1
Ref:
https://xoops.org/modules/newbb/viewtopic.php?topic_id=13891&forum=8#forumpost55849Inside 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
";
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
";
sqlite_query($this->db, $sql);
}
return true;