1
sudhaker
XoopsSessionHandler
  • 2003/11/18 19:44

  • sudhaker

  • Not too shy to talk

  • Posts: 117

  • Since: 2003/2/6 2



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...

2
sudhaker
Re: XoopsSessionHandler
  • 2003/11/30 6:58

  • sudhaker

  • Not too shy to talk

  • Posts: 117

  • Since: 2003/2/6 2


No one listening here...

Login

Who's Online

144 user(s) are online (96 user(s) are browsing Support Forums)


Members: 0


Guests: 144


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Apr 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits