Hugo Mota
Hugo Mota

Reputation: 11547

what's the best way to save sessions in a database?

i'm planning on making my own custom session handling functions. i want to save it in the database but i have some doubts.

so, what do you guys think? what do you suggest me to do?

Upvotes: 0

Views: 284

Answers (3)

nimmen
nimmen

Reputation: 111

Why would you want to permanently store session data? Usually people use different session handlers to make application faster (we use memcache for sessions, because our application is quite complex and distributed and we want it to run fast). I consider this requirement as bad application design, if you want to track your visitors in some way, there are a lot of better ways doing it. Or you are using session for the things it is not quite intended/suitable for. Of course i can imagine that there might be that kind of requirement, just i dont think that this is the case.

Upvotes: 0

Petah
Petah

Reputation: 46050

Yes it will normally be slightly slower than PHP's native session handler, however it shouldn't be noticeable. This is unless you are having problems with file locking issues (like Windows does)

Upvotes: 0

prodigitalson
prodigitalson

Reputation: 60413

I use DB sessions all the time with Zend and Symfony so its definitely viable, there will be a cost of course but most likely nothing significant.

Normally the way these handlers work is to use session_set_save_handler that way it works as normal except for the actual function called which writes the data. However pay attention to the warnings about object destruction.

Upvotes: 1

Related Questions