I'm building a Session class, and was wondering how to deal with expired sessions in the database. I was thinking about throwing a random number, for example between 1 and 1000, and if it is 1, then I delete all the expired sessions.
I guess this will be faster than reading a file or another table in the DB, to check if I have to delete the expired sessions. But I'm not sure if this will work fine when I have a lot of visits. I could increase the range of the random number, but I don't feel good depending on randomness, so I'm not sure this is the way to go.
A cron would be better indeed, but I wanted it to be auto-sufficient.
1 year 19 weeks ago