Page 1 of 1

Store session, file , database, memory, which better

Posted: Sun Jun 26, 2011 5:45 am
by coolesting
Hi, guys,
as the topic as i said, which better to save the session data, default method in php is file storage .
what do you think about this question.

Re: Store session, file , database, memory, which better

Posted: Mon Jun 27, 2011 9:44 am
by alex.barylski
There is no "better" only different. DB hosting is probably more secure and robust and scalable if configured properly. Files are more risky on shared servers, but require no additional implementation or library.

Cheers,
Alex

Re: Store session, file , database, memory, which better

Posted: Mon Jun 27, 2011 1:10 pm
by AbraCadaver
Also, suppose you want to display how many users are online or the usernames of the users online, etc. I don't know how you can achieve this with the file based sessions, but with a DB it is just a simple query.

Re: Store session, file , database, memory, which better

Posted: Mon Jun 27, 2011 1:31 pm
by social_experiment
AbraCadaver wrote:I don't know how you can achieve this with the file based sessions, but with a DB it is just a simple query.
Out of curiosity: wouldn't an SQLite file-based database be able to do this? I think if a choice has to be made, go with databases, in the long run it will probably save you a lot of hassles.

Re: Store session, file , database, memory, which better

Posted: Mon Jun 27, 2011 3:29 pm
by VladSun
AbraCadaver wrote:Also, suppose you want to display how many users are online or the usernames of the users online, etc. I don't know how you can achieve this with the file based sessions, but with a DB it is just a simple query.
:D
viewtopic.php?f=1&t=82659&p=460330#p460330

Re: Store session, file , database, memory, which better

Posted: Mon Jun 27, 2011 3:31 pm
by VladSun
alex.barylski wrote:Files are more risky on shared servers
One just needs to set the session files save path (if it isn't already set by the hosting company) to a path in his/her own directory in order to get fulll privacy.

Re: Store session, file , database, memory, which better

Posted: Mon Jun 27, 2011 4:53 pm
by superdezign
But the database is still more powerful since you have the ability to precisely control the death of those sessions. PHP holds onto session data past the expiration and is as limited as the GC.

Database is my personal preference, but it is also the slowest. Memory is the fastest to access, though it requires a bit of extra logic to set up and, AFAIK, has difficulty working on shared servers. The reason that the file method is the default is because it's a stable medium.