premiso Posted July 31, 2007 Share Posted July 31, 2007 Hello All, Have a question about storing data in session. I have a blog site with users of course. Instead of having to make a call to getUserData() each time I want user data inside a function (or defining it globally) I thought about storing the data in a session variable and doing one of two things. Keeping that throughout the lifetime of the session, and only re-querying if a change has been made since the request was pulled (Date field in the user table of last_modified) or just storing it in session and un setting the data each page. Not sure which (if any) is better. Most likely there will be about 20 fields stored, username, email, and some options the user is able to set which should only be boolean variables. I think storing it in session and testing against the timestamp would work great but before I start coding this for my whole site would like to know some input. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/62593-solved-storing-data-in-session/ Share on other sites More sharing options...
btherl Posted July 31, 2007 Share Posted July 31, 2007 The cost of pulling an entire row compared to pulling one column from the database is not much different. Not unless there is a LOT of data in that row. You may save some time in parsing the data though. I would expect you will see little difference though. But I could be wrong It's always difficult to predict performance. Another option is to store the data in a session, and let the script itself refresh the data only if the script itself makes a change to it. That means that if some other script modifies the user's data, the change won't show up. But you do save the trouble of checking to see if it's updated. Whether or not that works depends on your situation. Quote Link to comment https://forums.phpfreaks.com/topic/62593-solved-storing-data-in-session/#findComment-311595 Share on other sites More sharing options...
premiso Posted August 1, 2007 Author Share Posted August 1, 2007 I guess either way I am making a trip to the database. The goal is to have the options available globally (via session). So I guess checking against the timestamp works and just keep the data in session will be how I go. It will definitely be under 5KB so I doubt there will be a problem. Thanks for the input bud. Quote Link to comment https://forums.phpfreaks.com/topic/62593-solved-storing-data-in-session/#findComment-312415 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.