PHP Sessions or Constant sql queries?

software development

#1

I’m curious which is preferred by dreamhost. If I use PHP sessions on a fairly high traffic site and the session doesn’t get ended correctly I’m afraid they may not get garbaged for quite some time creating a large amount of leftovers on the server.

On the otherhand I could query the sql server on each page that requires info.

Could pass it in the hyperlink, but this won’t serve my purpose

My question is would sessions on a high traffic site be okay or would constant mysql queries be better? Anyone have any opinons?

I want to create the least load possible.


#2

Sessions, easily. The session information isn’t ‘left over’, it is destroyed when the browser is shut down, unless otherwise specified in your code.

I find sessions to be the most useful and easily managable set of functions in PHP. Sessions, for sure.


#3

You can perform analysis on the sessions in a table though. Without having fields for number of users online in a db that gets updated when a session starts, you can log ips, user log in information etc.
The server and PHP will clean any stale sessions after a certain number of minutes. Not sure how long it is on these servers.