I've searched all over google for an idea on how this works.
I'm trying to setup a page where people can only download a file every 20 seconds or so. The download is called from a function which checks if they have downloaded anything within the past 20 seconds.
My idea is to get their ip address and insert it into a db with the date/time.
What's puzzling me is how I can check and update the database every ten seconds. I was thinking of using a cron job but the lowest it can go to is minutes.
I want to hear the opinions of skilled programmers on how to do this the most efficient way.
Thanks
No offense, but your wording is confusing. I assume that you are trying to conserve bandwidth by limiting the number of downloads per user within the past 20 seconds?
If this is the case.... why 20 seconds? This is not going to do much to conserve bandwidth, especially when dealing with large files (in which case it would be better to limit the bytes downloaded, rather than the number of files).
Using CRON or similar apps shouldn't be needed to limit file transfers. Also, using IP authentication isn't the best solution either (ie. AOL users sometimes get their IP address changed as they surf, and the user might be behind a proxy, which prevents IP-authentication(more than one person can have the same IP)).
Try to use cookies to authenticate users. If you insist on using the IP, then, at the very least, include the HTTP_USER_AGENT along with the IP for better identification.
Why do you need to automatically update the database? Just record the time of that user's last download. If their next download attempt is less than 20 seconds later, then deny them access.