I was using mysql to check if the user was logged in or not, but I received an email from my hosting company saying that I had exceeded the mysql queries limit and the cost to upgrade the mysql queries limit to 150000 per hour was $240/year.
Now, I need an alternative way to check if the user’s logged in or not, like writing the user’s timestamp in a file, but I don’t know the best way to do it… And I don’t even know which tags I put on this post…
So, could you please help me with this problem?
It is rather odd that your host has a mysql query limit, but back to your question;
I will take a guess that you are not just trying to see if a user is logged in locally, but rather, having another account see that the user is logged in, which would require a database call, not a $_SESSION (which is maintained on a per-user basis).
If, however, we make the assumption that you want to do this outside of the database, you can generate the end HTML result when a user logs in or out. Keep a table in the database with the status of the users, but whenever a user logs in or out, make ONE query to that table, and generate, say, your HTML list of logged in users. Save the output to a file, and when you need to render a page, include that file instead of making a database call.
It’s not completely removing the MySQL database, but it is reasonably reliable, and should significantly reduce your number of database queries.