tgavin Posted February 6, 2008 Share Posted February 6, 2008 I'm re-factoring my app and am looking at using sessions instead of constants. Currently, I have about 25 or so constants that define different parameters of the app. This has been working OK, but I'm starting to run into some problems with expansion, so thought sessions would be perfect. I'd just put them into an array, like so <?php $_SESSION['template'] = array(); $_SESSION['template']['name'] = $row_template['template_name']; $_SESSION['template']['auto_format'] = $row_template['auto_format']; ?> This is working just fine. However, I'm wondering about performance. If I start storing all these items in sessions, how much can I do before the server, or user starts experiencing problems, or performance issues? Am I better off storing them in arrays? Or should I register each setting as its own session? Quote Link to comment Share on other sites More sharing options...
trq Posted February 7, 2008 Share Posted February 7, 2008 If these settings aren't user specific there is no point storing them in the $_SESSION array. Sessions are specifically designed to store data relating to a particular user. Quote Link to comment Share on other sites More sharing options...
tgavin Posted February 7, 2008 Author Share Posted February 7, 2008 Unfortunately I'm encountering problems with certain aspects of the app because it needs to remain flexible. One major drawback has been the server path to the site root. I can set this in one part of the app, like a config file, but because of includes and user-defined templates this has been a major nightmare. Storing that in a session has been perfect. I know that it's easy to say this is a design flaw, but I have not come across anything that will allow me to point to the site root, then to a particular sub-directory IF the user has defined one. So, storing items in sessions has really proven quite flexible for me. If there's a better way I'm all open to hearing about it. That's why I designed everything in constants to begin with - so that I wouldn't have to worry about global vars, functions, etc. thanks Quote Link to comment Share on other sites More sharing options...
Acs Posted February 10, 2008 Share Posted February 10, 2008 Why not just do everything in the index.php? Instead of directories and subdirectories, just use require to get the files and use them in index.php, with this approach you will always know where you are! Quote Link to comment Share on other sites More sharing options...
TheFilmGod Posted February 19, 2008 Share Posted February 19, 2008 Whenever creating a new php file I have 2 variables. $root = "../"; - to root index directory $element = "../element"; - to include() files directory Whenever I need to include() a file, I use include(($element).'filename.php'); In the actual file that I included (filename.php) I might need to reference to an image or something... so I use $root Quote Link to comment Share on other sites More sharing options...
jazz Posted February 23, 2008 Share Posted February 23, 2008 There is no limit to the session variables you can use. Well, if you use a million of them, you 'll find that your hard disk is not that empty anymore. ;D Quote Link to comment Share on other sites More sharing options...
Xeoncross Posted February 26, 2008 Share Posted February 26, 2008 5 session variables is "too many". Just because you are having trouble with paths doesn't mean you should get sloppy with sessions. Here is a line out of my system that defines the root dir from TWO levels down in the "/site/config.php" file: <?php // Absolute file system path to the CX root define('SITE_DIR', realpath(dirname(__FILE__). "/../../")); ?> Quote Link to comment Share on other sites More sharing options...
NikkiLoveGod Posted March 13, 2008 Share Posted March 13, 2008 Sorry if this is pulling up a too old thread, but this is quite relevant to me atm. So, you said 5 session variables is "too many"? How come? Why is this too many? I am working on a project, that uses ALOT of session variables, ( i might say around 50, might be a little less ). The project is very poorly planned and done to begin with, but that really is quite the only way of storing information from page to page, or atleast, the only one I am familiar with. The project has more than 120 .php files ( yes, 115 of them kinda repeats it self ) and have a 'path info', like what you have selected previously stored in sessions and so on. I havent really seen any sluggish performance on that, though I havent benchmarked at all. So, other than the fact that it is really messy, I dont see a problem using alot of session variables. Maybe someone could prove me wrong? ps. I have started to rewrite the whole project to have 5 different files, and generate forms and such, instead of putting them all into a different files Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted March 13, 2008 Share Posted March 13, 2008 So, other than the fact that it is really messy, I dont see a problem using alot of session variables. Maybe someone could prove me wrong? You just answered your own question. Quote Link to comment Share on other sites More sharing options...
NikkiLoveGod Posted March 14, 2008 Share Posted March 14, 2008 I quess I did I was wondering if there were any other reason in it, that I am not aware of. Now, would you still consider it to be messy, if you store the information, for example, my 50 session variables, into a, lets say 4 or 5 session arrays? Or can you think of a way to store that information some other way, than sessions, database or files Quote Link to comment Share on other sites More sharing options...
Jenk Posted March 14, 2008 Share Posted March 14, 2008 If these settings aren't user specific there is no point storing them in the $_SESSION array. Sessions are specifically designed to store data relating to a particular user. Almost, they are specific to the currently active session. Users change within the same session. Quote Link to comment Share on other sites More sharing options...
tendrousbeastie Posted March 16, 2008 Share Posted March 16, 2008 I'd be interested to here any comments on the performance side of session vars. Let's assume that there are occasionally good reason for using a lot of session vars, is this going to have adverse performance implications? Does PHP cache the vars on the server, or is there a HDD read each time the var is accessed in a script? Quote Link to comment Share on other sites More sharing options...
Jenk Posted March 17, 2008 Share Posted March 17, 2008 Depends on your structure of session storage. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.