Store session, file , database, memory, which better

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Store session, file , database, memory, which better

Postby coolesting » Sun Jun 26, 2011 5:45 am

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.
User avatar
coolesting
Forum Newbie
 
Posts: 13
Joined: Thu Sep 02, 2010 12:36 am

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

Postby alex.barylski » Mon Jun 27, 2011 9:44 am

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
alex.barylski
DevNet Evangelist
 
Posts: 6259
Joined: Tue Dec 21, 2004 6:00 pm
Location: Winnipeg

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

Postby AbraCadaver » Mon Jun 27, 2011 1:10 pm

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.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
User avatar
AbraCadaver
DevNet Master
 
Posts: 2572
Joined: Mon Feb 24, 2003 11:12 am
Location: The Republic of Texas

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

Postby social_experiment » Mon Jun 27, 2011 1:31 pm

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.
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
User avatar
social_experiment
DevNet Master
 
Posts: 2775
Joined: Sun Feb 15, 2009 12:08 pm
Location: .za

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

Postby VladSun » Mon Jun 27, 2011 3:29 pm

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
User avatar
VladSun
DevNet Master
 
Posts: 4294
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

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

Postby VladSun » Mon Jun 27, 2011 3:31 pm

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.
User avatar
VladSun
DevNet Master
 
Posts: 4294
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

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

Postby superdezign » Mon Jun 27, 2011 4:53 pm

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.
User avatar
superdezign
DevNet Master
 
Posts: 4135
Joined: Sun Jan 21, 2007 12:06 am


Return to PHP - Theory and Design

Who is online

Users browsing this forum: No registered users and 3 guests