SyncViews Posted April 24, 2008 Share Posted April 24, 2008 Right now almost every page is making the same sql querys to get things like paths to the users template directory etc. eg: $result = $mysqli->query("SELECT style_path, style_name FROM styles WHERE style_id=$_SESSION[style]"); This seems a waste of resources and I'm certain it would be more efficent just to keep the whole lot in memory as an array... $styles 0 => 'name' => 'Default' 'path' => 'styles/default' 1 => 'name' => 'Deep Space' 'path' => 'styles/deepspace' So is there someway I can have this array present accross all my scripts? A shared global if you like. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted April 24, 2008 Share Posted April 24, 2008 Make a function that stores the user's info in a session variable if it's not already set. Quote Link to comment Share on other sites More sharing options...
SyncViews Posted April 24, 2008 Author Share Posted April 24, 2008 But then I still have a copy for each user. Is it posible to have just one copy of it for everyone? (not so much for this data but for some larger data this could massivly reduce the amount of ram being used...) Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted April 24, 2008 Share Posted April 24, 2008 Each request to a web server is separate from every other request and once a request has been serviced all the resources used on that page are destroyed. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted April 24, 2008 Share Posted April 24, 2008 Oh, by the way, thanks for making this topic, because it prompted me to rewrite my retrieve_user_info function on my little test application I wrote. I meant to do it yesterday, but I procrastinated. I had it so it queried the database EVERY single page to retrieve their info, but now I just store it in the session (and query) if it's not already set. Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted April 24, 2008 Share Posted April 24, 2008 Web servers are stateless. The only way to share data between separate users is to store it in a database, a disk file, or a memory cache. Since, you already have it in a database, your choices would be to cache it in a disk file or a memory cache. Sessions allow data for one visitor to be propagated between pages or between refreshes of a single page but sessions are not shared between separate users (and the session data is stored in files by default, so even if you could share session data between visitors, there is no advantage over caching the data in a disk file.) Quote Link to comment Share on other sites More sharing options...
DarkWater Posted April 24, 2008 Share Posted April 24, 2008 I rarely see people use the word propagated correctly. =P 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.