mshallop Posted March 6, 2006 Share Posted March 6, 2006 Question - in an application of hundreds of php source scripts, does it make more sense to object-ify your session storage via mySQL instead of the _SESSION functions? Granted, some limited data would still have to be session-ized (at the minimum, the user/group id), but if you're storing several tables worth of data in a session, at what point does it become more efficient (if it does) to load everything from a database instead via class functions?Factor in considerations such as a load-balanced server environment....does this change the equation?Just curious if anyone else has dealt with this....--Mike Quote Link to comment Share on other sites More sharing options...
wickning1 Posted March 6, 2006 Share Posted March 6, 2006 Load-balanced servers will definitely make a difference. PHP sessions are stored on disk, so different web servers will not know about each other's sessions.I don't think there are significant performance differences either way, as long as your data is stored efficiently in both cases. You'll have to make more tcp/ip connections to get the data from mysql, but mysql has data access/caching optimizations that will help neutralize that cost. Quote Link to comment Share on other sites More sharing options...
txmedic03 Posted March 7, 2006 Share Posted March 7, 2006 Well, it all depends on your needs, but I handle all of my sessions with mysql. I use session_start() to begin the session with a unique sid then session_id() to reference the row in the sessions table. Every user has a row in this table so I can track current users viewing the site. If the user does not load any pages with in 10 minutes the row is removed from the table. I do this by using time()+600 and comparing it to time(). if time() >= {value retrieved from mysql for time()+600} then expire delete row from table otherwise update row with time()+600 to continue session for 10 minutes from now. Incidently, you do not have to store your username/password or anything in the $_SESSION since the session_id() returns a unique identifier for your sessions. If you would like more detailed information on the way I did the user tracking and handled the sessions so you can benchmark it against storing data in $_SESSION, let me know and I would be happy to share an example script with you. 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.