Jump to content

Recommended Posts

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
Link to comment
https://forums.phpfreaks.com/topic/4214-sessions-v-sql-storage-performance/
Share on other sites

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.
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.
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.