{"id":15649244,"url":"https://github.com/akirk/php-ratelimiter","last_synced_at":"2025-07-04T08:05:48.597Z","repository":{"id":8123456,"uuid":"9540256","full_name":"akirk/php-ratelimiter","owner":"akirk","description":"A small class that uses Memcache to allow only a certain number of requests per a certain amount of minutes.","archived":false,"fork":false,"pushed_at":"2018-04-26T12:43:31.000Z","size":128,"stargazers_count":39,"open_issues_count":4,"forks_count":14,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-30T16:13:02.376Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://alexander.kirk.at/2013/04/19/add-a-rate-limit-to-your-website/","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/akirk.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-04-19T07:35:24.000Z","updated_at":"2024-04-28T08:11:17.000Z","dependencies_parsed_at":"2022-09-11T02:23:09.601Z","dependency_job_id":null,"html_url":"https://github.com/akirk/php-ratelimiter","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/akirk/php-ratelimiter","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akirk%2Fphp-ratelimiter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akirk%2Fphp-ratelimiter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akirk%2Fphp-ratelimiter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akirk%2Fphp-ratelimiter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/akirk","download_url":"https://codeload.github.com/akirk/php-ratelimiter/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akirk%2Fphp-ratelimiter/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263472278,"owners_count":23471812,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-03T12:29:00.277Z","updated_at":"2025-07-04T08:05:48.569Z","avatar_url":"https://github.com/akirk.png","language":"PHP","funding_links":[],"categories":["安全( Security )"],"sub_categories":[],"readme":"php-ratelimiter\n===============\n\nA small class that uses Memcache to allow only a certain number of requests per a certain amount of minutes.\n\nThe class works around the problem that the timeframe is constantly moving, i.e. every new minute the timeframe is different. See my [blogpost](http://alexander.kirk.at/2013/04/19/add-a-rate-limit-to-your-website/).\n\nThe code is released under an MIT license.\n\nUsage\n-----\n\n```php\n$rateLimiter = new RateLimiter(new Memcache(), $_SERVER[\"REMOTE_ADDR\"]);\ntry {\n\t// allow a maximum of 100 requests for the IP in 5 minutes\n\t$rateLimiter-\u003elimitRequestsInMinutes(100, 5);\n} catch (RateExceededException $e) {\n\theader(\"HTTP/1.0 529 Too Many Requests\");\n\texit;\n}\n```\n\nRemarks\n-------\n\nThe script creates a memcached entry per IP and minute.\n\nIf you want to protect multiple resources with different limits, use the third parameter of the constructor to namespace it:\n\n```php\n// script1.php\n$rateLimiter = new RateLimiter(new Memcache(), $_SERVER[\"REMOTE_ADDR\"], \"script1\");\ntry { ... }\n// script2.php\n$rateLimiter = new RateLimiter(new Memcache(), $_SERVER[\"REMOTE_ADDR\"], \"script2\");\ntry { ... }\n```\n\nYou can also use something else as a second parameter, for example a `session_id` to limit the requests per user instead of IP address.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fakirk%2Fphp-ratelimiter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fakirk%2Fphp-ratelimiter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fakirk%2Fphp-ratelimiter/lists"}