{"id":16101739,"url":"https://github.com/kelunik/rate-limit","last_synced_at":"2026-03-14T11:02:16.880Z","repository":{"id":57005475,"uuid":"55863350","full_name":"kelunik/rate-limit","owner":"kelunik","description":"Rate Limiting for Amp.","archived":false,"fork":false,"pushed_at":"2023-09-04T17:58:33.000Z","size":16,"stargazers_count":12,"open_issues_count":0,"forks_count":4,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-10T18:50:51.512Z","etag":null,"topics":["amphp","php","rate-limit"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kelunik.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-04-09T19:36:20.000Z","updated_at":"2024-06-19T16:49:10.000Z","dependencies_parsed_at":"2022-08-21T13:50:53.221Z","dependency_job_id":null,"html_url":"https://github.com/kelunik/rate-limit","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kelunik%2Frate-limit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kelunik%2Frate-limit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kelunik%2Frate-limit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kelunik%2Frate-limit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kelunik","download_url":"https://codeload.github.com/kelunik/rate-limit/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221708921,"owners_count":16867651,"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":["amphp","php","rate-limit"],"created_at":"2024-10-09T18:50:52.979Z","updated_at":"2025-09-23T15:12:01.563Z","avatar_url":"https://github.com/kelunik.png","language":"PHP","funding_links":[],"categories":["Throttling"],"sub_categories":["Tunnel"],"readme":"# rate-limit\n\n![License](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)\n\n`kelunik/rate-limit` is a rate limiting library for [Amp](https://github.com/amphp/amp).\n\n## Installation\n\n```bash\ncomposer require kelunik/rate-limit\n```\n\n## Usage\n\nYou're in full control of any actions when the rate limit is exceeded. You can also already warn the user before he exceeds the limit.\n\n```php\n$current = $this-\u003erateLimit-\u003eincrement(\"{$userId}:{$action}\");\n\nif ($current \u003e $this-\u003elimit) {\n    // show captcha or error page or do anything you want\n} else {\n    // request is within the limit, continue normally\n}\n```\n\nIf you want to expose the limits, e.g. in an HTTP API, you can also request the reset time for a given key.\n\n```php\n$current = $this-\u003erateLimit-\u003eincrement(\"{$userId}:{$action}\");\n\n$response-\u003esetHeader(\"x-ratelimit-limit\", $this-\u003elimit);\n$response-\u003esetHeader(\"x-ratelimit-remaining\", $this-\u003elimit - $current);\n$response-\u003esetHeader(\"x-ratelimit-reset\", $this-\u003erateLimit-\u003egetTtl(\"{$userId}:{$action}\"));\n```\n\n`RateLimit::getTtl()` returns the seconds until the limit is reset. If you want to return the absolute time, you can just add `time()` to that value.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkelunik%2Frate-limit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkelunik%2Frate-limit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkelunik%2Frate-limit/lists"}