cranky Posted March 20, 2011 Share Posted March 20, 2011 I've been trying to find a way to have the server collect session garbage more often when there are few users registered, and the other way around. It took me a while, but I've come up with this: $result = mysql_query("SELECT COUNT(*) FROM users") or ErrorHandlingFunction('foo bar')); $numberofusers = mysql_result($result, 0); $divisor = 100/$numberofusers; ini_set('session.gc_divisor', $divisor); ini_set('session.gc_probability', 1); Will this work? Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted March 20, 2011 Share Posted March 20, 2011 There's no good reason to be doing this. In fact, by reducing the probability that garbage collection will run, as you add more users, when garbage collection does eventually run, it will have to take a greater amount of processing time because there will be more session data files to examine and a greater percentage of those will be old enough to delete and it will take more time to delete them. It is best to just leave the probability at a fixed and reasonable value. Quote Link to comment Share on other sites More sharing options...
cranky Posted March 20, 2011 Author Share Posted March 20, 2011 Thank you for your quick reply! There's no good reason to be doing this. But will it work? I am certainly not getting any errors. Purely hypothetically, if I would do this: $divisor = $numberofusers; What will happen if the number of users goes over a 100? Can divisor be set to a number higher than 100? It is best to just leave the probability at a fixed and reasonable value. Which would be? Quote Link to comment Share on other sites More sharing options...
cranky Posted March 20, 2011 Author Share Posted March 20, 2011 There's no good reason to be doing this. But will it work? I am certainly not getting any errors. Hmm, I now see that users are being logged out in the middle of their session, although session.gc_maxlifetime is set to 0 (doesn't this mean until the end of the session, like for cookies?). I was hoping to make sessions infinite (until user navigates away from the site), because I am handling login lifetime a different way (if (time() - $_SESSION['last_activity'] > $set_sessionLifetime)){}). 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.