I'm looking for a small script that I can use to limit the number of downloads per day for a specified file, or limit the bandwidth for said file per day.
Any Ideas?
:D
Two practical ways to solve this — and which to pick depends on whether you need a global per-file/day quota (application-level) or raw per-connection/per-request bandwidth throttling (server-level). was right to suggest checking the web server first: server modules can throttle cheaply; an app-level script gives precise per-file or per-account daily limits.
Server-level (best for bandwidth)
limit_rate/limit_conn, and CDNs can enforce transfer caps. These are efficient because the webserver handles streaming; they are not great if you need a single shared daily quota across many requests unless the server module explicitly supports per-resource accounting.Application-level (best for per-file/day counts or byte quotas)
download.php?id=... endpoint that:CREATE TABLE download_counts (
file_id VARCHAR(255) NOT NULL,
day DATE NOT NULL,
count INT UNSIGNED NOT NULL DEFAULT 0,
bytes BIGINT UNSIGNED NOT NULL DEFAULT 0,
PRIMARY KEY (file_id, day)
); INSERT INTO download_counts (file_id, day, count, bytes)
VALUES ('file123', CURRENT_DATE, 1, 12345)
ON DUPLICATE KEY UPDATE count = count + 1, bytes = bytes + 12345; Notes and cautions
Jump to Post— Comatose 290I'm sure I could come up with a hack job of a way, but I know there is a better way (maybe with the web-server's configuration?)
I'm sure I could come up with a hack job of a way, but I know there is a better way (maybe with the web-server's configuration?)
do you know where i could get a php script that would do this?
Did you check if the webserver's settings could do this?
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.