tags:

views:

58

answers:

3

I currently use sessions pretty heavy and I am re-coding my network site right now. 1 thing I have done is made a session class that has some simple methods for example here is how I would retrieve session data using my class.

$session = new Session();

// to set a session I would use this
echo $session->set('user_id');

// to view a session's data
echo $session->get('user_id');

Now this is basicly the same as setting a viewing a session variable the regular way except I run it through this session class, the purpose I have is to make it more flexible. I figure if all session data is ran through that class on a big site, then all I would have to do to change it's source to use a cache or memcache or a database is to just change the session class file.

SO in reality I really don't have much gain in using a class/methods for my session data at the moment but some day I might.

My question is, on a very high traffic site, would it be better to not be making the extra method/class call everytime I need to show sessions data?

+1  A: 

Don't prematurely optimize. Chances are you will have inefficiencies or algorithm problems that cost seconds at a time, so stop worrying about saving a millisecond here or there.

Paul Tomblin
Sometimes my girlfriend accuses me of prematurely optimizing. :)
Chuck Vose
I know this is generally the case and I deff have more things to work on but I have been coding this site and optimizing it for over 2 years and every millisecond adds up on a high traffic environment. I am currently re-coding most of my work though and I have heard that function calls do hurt performance slightly but I am new to using classes/methods so I am not sure about performance of classes in general. Thanks for the tips
jasondavis
A: 

You're fine. You want to use static or some other persistent variable on data that can be cached during the life of the request but in general on high performance sites the backend code is usually not the thing you have to worry about.

Check out this article for what I mean about backend performance.

Chuck Vose
A: 

You are using a pattern that is exemplified in several frameworks, one of which is the framework I personally use, Zend Framework.

The comments about optimization are correct, the performance hit of the session stuff you are doing is liable to be so minute that it wouldn't matter in the end. There are numerous benefits that having a session class can provide for you, and the frameworks common use of a session object as opposed to simple session access via functions should show that clearly.

Regards,

JC