Page 1 of 1

Need advice: Effenciency, Sesions variables and databases

Posted: Sun Oct 26, 2008 6:29 am
by Weemen
Hey all,

Well I finally found a good php forum wooohoo, I hope you can give me a little feedback on an idea that I have.

I'm looking for an effecient way to make website menu. At the moment I can bring it back to 1 query per page view
cause I've made an extra database table where the menu is sorted out for me which already was a great improvement
with my very first solution. (Aprox 4 per pageview).

I was wondering if the following is possible. I'm thinking to store the tree at my session variable. In such situation I don't
have to do any query at all. I'll update the tree at the moment that I made a change at my CMS. This solution gives me two problems

1) Is it possible to update a session variable (or a least giving a sign to update tree) in all exisisting sessions from a specific domain?
2) Are there any arguments for not choosing this solution?

Maybe an extra question could be, what is in general good to store at a session variable and what is in general bad to store at session
variable. I'll would like to choose for my solution cause I think the session variable is faster then the database but I'm not sure if it's the
smartest idea to do

All ready thanks for reading

Leon

Re: Need advice: Effenciency, Sesions variables and databases

Posted: Sun Oct 26, 2008 12:07 pm
by Christopher
I don't think there is any rule about what to store in sessions. Obviously it is data that only should exist for a session's length of time. Something like you menu could be built and saved in the session to save the query each request. I don't think there is an easy to update on variable in all sessions.

Re: Need advice: Effenciency, Sesions variables and databases

Posted: Mon Oct 27, 2008 9:12 am
by Weemen
Well I might found the answer, I think it's possible to override the storage path of the session files. If I can store them in a local folder then I can change the session files. Not sure if it's works but I'll give it a try :)

The bad is that's a damn dirty trick and if it's go wrong then all my sessions are messed up :)

Re: Need advice: Effenciency, Sesions variables and databases

Posted: Mon Oct 27, 2008 11:14 am
by allspiritseve
Weemen wrote:Well I might found the answer, I think it's possible to override the storage path of the session files. If I can store them in a local folder then I can change the session files. Not sure if it's works but I'll give it a try :)

The bad is that's a damn dirty trick and if it's go wrong then all my sessions are messed up :)
You might find it a bit easier to store your sessions in the db, and make modifications on those rows:

http://shiflett.org/articles/storing-se ... a-database

Edit: but... before you go to all the trouble, consider not trying to optimize until you really have performance problems. I find it hard to believe retrieving a simple menu from the db is noticeably slowing your scripts.

Re: Need advice: Effenciency, Sesions variables and databases

Posted: Mon Oct 27, 2008 12:26 pm
by Weemen
Hey very special thnx for that link. That's very interesting article!!!

For me, my goal is just looking for maximum effeciency. It's not that my scripts are slow :)
I like these troubles, it's gives me a challenge :)

Another thnx for the article :D

Re: Need advice: Effenciency, Sesions variables and databases

Posted: Mon Oct 27, 2008 2:14 pm
by Hannes2k
Hi,
1) That's normaly not possible. There are some workarounds, but you shouldn't use it.
2) A sql database can perform thousands of queries per second, so one sql query more per page view shouldn't be a problem.

Re: Need advice: Effenciency, Sesions variables and databases

Posted: Thu Oct 30, 2008 9:43 am
by josh
Session data is saved by PHP as a serialized object by default, also sessions are intended for data specific to a single user. For something site wide like the menu I'd put it in the database and just use a regular SQL query to build an array on each page request