CodeIgniter Forums
CodeIgniter 1.7 Session Class - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forum-21.html)
+--- Thread: CodeIgniter 1.7 Session Class (/thread-12163.html)



CodeIgniter 1.7 Session Class - El Forum - 10-08-2008

[eluser]drewbee[/eluser]
I know this may seem a bit unorthodox, and I get a bit crazy about performance especially in relation to queries, but why is the session class doing a database query on every single set_userdata() and unset_userdata() call?

A far more optimized version would hold all updates until the end of script execution. I am rather tired right now, so I may be mis-reading the code, but this is what it looks like to me, then makes an additional query to update the last_active and session_id column after the should the configuration option sess_time_to_expire passes.

The way I see everything flowing it should be a pretty simple top to bottom level

IE.
Query database for any session data > do all in-process updates local to the object > at end of script update all changes to the database. Their shouldn't be anymore then two queries top to bottom in the session class (select and update (or insert if a creation)).

Is their any reason for this? It seems like way more overhead then what is needed... please tell me I am just reading code wrong...

Thoughts?


CodeIgniter 1.7 Session Class - El Forum - 10-08-2008

[eluser]Randy Casburn[/eluser]
Hi Drew,

The session class is not stateful so it has no sense of when the script has finished or not finished. As a foolish coder, I can put an 'exit' statement anywhere in my code, a controller for instance, that would negate the session updates.

So in order to ensure stateful transfers to the database, updates are done in synchronous mode, in real time, or as they occur.

Hope this is helpful,

Randy


CodeIgniter 1.7 Session Class - El Forum - 10-08-2008

[eluser]drewbee[/eluser]
Ah... part of me (well ok... all of me Smile ) is living in PHP 5 world. The __destruct() method would be able to take care of this beautifully. I guess this leaves no options open for the PHP 4 world though.

As soon as everything starts shutting down, even with an exit statement (or end of script execution) this method would be called to do its final update, all the while any data updates, removals, changes etc etc would be pulled from the local object.

Off I go to re-write the session library. Smile


CodeIgniter 1.7 Session Class - El Forum - 10-08-2008

[eluser]Randy Casburn[/eluser]
Whatever....I'd be really interested to know how many 10s of minutes it takes and how many microseconds you save in processing time.

Randy