Welcome Guest, Not a member yet? Register   Sign In
Need help reducing database requests to check if a user is logged in
#6

[eluser]BrianDHall[/eluser]
It's perfectly fine and minor for your application to use 1 database call to check to see if the user is logged in on every page request. The alternative is using an optimization in the form of a time-limited token, so it logs them in, gives them a token good only for 5 minutes, then re-validates them when the token expires.

This however is a not very trivial way to reduce a single database call, which is silly to do in the development phase - it might never even be worth addressing if/when it comes time to optimize for performance.

However, it IS reasonable to store the variable at the beginning of script execution, so in your logged in function set yourself a variable good only until the script finishes executing. If it is set then you don't run the database call, you just have your logged_in() function return true.

This solves the issue of running the same database call over and over in a loop, as the database is contacted only once the first time logged_in() is called on a particular page.


Messages In This Thread
Need help reducing database requests to check if a user is logged in - by El Forum - 12-26-2009, 10:09 AM



Theme © iAndrew 2016 - Forum software by © MyBB