Page 1 of 1

Session management in 1 database on shared hosting

Posted: Sun Nov 12, 2006 5:51 am
by GeertDD
A quick question that just crossed my mind. Having a shared hosting package, I've been storing my sessions in a database for some time now. Works great. The thing is that in every domain pointer's database I created a new table called "_sessions".

Now I thought: why not create one central database that stores all sessions for every domain on my account?

Advantages? No need to create that same "_sessions"-table over and again. More generic setup. Keeps databases 'cleaner'.

Disadvantages?

(As far as I know, by default all the sessions on shared hosting are stored in the tmp/ directory so I guess storing all my sessions in one database should be no problem. Or I am overlooking something here?)

Posted: Sun Nov 12, 2006 7:06 am
by feyd
You're not overlooking much of anything. The session id will generally be unique across the server.

Posted: Sun Nov 12, 2006 7:25 am
by GeertDD
Great. However, I just did think of some disadvantages.

I have a field called "userid" in my sessions table. That way I can easily extract data for stuff like "who is online" pages. When using a different database for storing sessions, joining the sessions table with the users table is not possible anymore.

Posted: Sun Nov 12, 2006 7:29 am
by feyd
Why wouldn't be possible? If you're worried about having them selectable with respect to each domain then you could simply store a domain reference (of some fashion) in the table at the time of creation.

Posted: Sun Nov 12, 2006 7:37 am
by GeertDD
You're right about that domain reference. I did not even think about that yet myself.

I was wondering whether it would be possible to link two tables that are in a different database.

Posted: Sun Nov 12, 2006 7:57 am
by feyd
It's certainly possible. Although you may need to build an artificial link via logic in your PHP code.

Posted: Sun Nov 12, 2006 9:20 am
by GeertDD
You mean like first selecting the online user IDs from the sessions table. Then selecting the usernames and other info from the users with those ID's. However, I don't feel like going through the hassle of splitting this up, and adding domain references, etc.

This topic was just a quick thought of mine. Now I know the intended setup should be possible, but in the end I prefer to leave things as they are. It still works after all. Thank you for the input, feyd.