Re: SESSION variables: How much is too much?

From: Date: Wed, 08 Jul 2009 18:45:42 +0000
Subject: Re: SESSION variables: How much is too much?
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-295035@lists.php.net to get a copy of this message
Shawn McKenzie wrote:
D.M.Jackson wrote:
Hi,
    I'm trying to learn php mostly by reading the docs and pulling through other peoples projects for reference examples.  One particular application I'm looking at has a ton of variables being handled through the SESSION global variable, probably about 25 or so variables.  That just seems like alot.
    Since I'm pretty new to php I was wondering if this was typical and acceptable or if there was another best practice for maintaining large amounts of information throughout a session, like maybe persisting a temporary object in the database and passing a connection...or something. Or is just passing around a pile of variables directly in the SESSION object better?
Thanks, Mark
There is no difference between using session vars and storing vars in a file/db and retrieving them every page load yourself. It's really the same thing except sessions are more automagic. The main differences are that you of course reduce some overhead if you only need certain vars on certain pages or if you need them infrequently then you can store/retrieve them yourself. As far as a large amount of large objects, if you don't need them every page load then you may want to look at stuffing them in a db and only retrieving then when needed.
Shawn's right, just start using them. I was reluctant when I first started using PHP just because they seemed so special. Now, I use them for just about every page in an application. In fact, I'd like to session constants. Al.........

« previous php.general (#295035) next »