I've got a person's username, and that he is permitted ten demands daily. Every single day the demands return to ,and old information is unnecessary.

What's the easiest method to do that?

This is one way that involves mind, but I don't know whether it's the easiest way
(two fields, today_date, request_count):

  1. Query the DB for that date of last request and ask for count.
  2. Get result and appearance whether it was today.
  3. If today, look into the request count, if under 10, update query database to ++count.
  4. Otherwise today, update the DB with present day date and count = 1.

Can there be one other way with less DB queries?

I believe your option would be good. You'll be able to totally reset the rely on every day basis too. That will help you to skip a column, but you will have to operate a cron job. If you will find many customers that will not have demands whatsoever, it's pointless to totally reset their count every day.

But whichever you choose, both solutions are extremely similar in performance, data size and development time/complexity.

Only one column request_count. Then query this column increase it. So far as I understand with saved methods this might be possible in a single query. Even when not, it will likely be just two. Then produce a cron job, that calls a script, that starts over the column to 0 every single day at 00:00.

To spare you some demands towards the DB define

  1. the utmost quantity of demands daily permitted.
  2. the very first day open to the application (date offset).

Adding a requestcount area towards the database per user.

Around the first request obtain the count in the db.

The count is definitely the amount of your day increased using the maximum + 1 of demands daily as well as the actual demands with that user:

   day * (max + 1) + n

Therefore if on first request the count in the db is really greater than permitted, block.

Otherwise whether it's less than the present day base, totally reset to the present day base (within the PHP variable)

And total. Store this value in to the DB.

This really is one read operation, and just in case the request continues to be valid, one write operation towards the DB per request.

There's you don't need to operate a cron job to wash this up.

That's really just like you intend inside your question, however the day details are area of the counter value. So that you can do more with one value at the same time, while counting track of +1 per request still works best for the block.

You need to consider that every user might be inside a different time zone than your server, which means you can't just keep count or even the "day * max" trick. Try to obtain the time offset and so the start of user's day could be saved inside your "quotas" database. In mySQL, that will seem like:

`start_day`=ADDTIME(CURDATE()+INTERVAL 0 SECOND,'$offsetClientServer')

Then simply just take a look at this time around next time you look into the quota. The quota check can be completed in one query.