{"id":13828306,"url":"https://github.com/beyondcode/laravel-fixed-window-limiter","last_synced_at":"2025-07-09T06:31:32.495Z","repository":{"id":56950784,"uuid":"179824408","full_name":"beyondcode/laravel-fixed-window-limiter","owner":"beyondcode","description":null,"archived":true,"fork":false,"pushed_at":"2020-01-28T08:45:07.000Z","size":12,"stargazers_count":68,"open_issues_count":0,"forks_count":0,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-07-03T19:52:42.548Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/beyondcode.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-04-06T11:24:13.000Z","updated_at":"2024-03-19T10:22:30.000Z","dependencies_parsed_at":"2022-08-21T08:21:01.467Z","dependency_job_id":null,"html_url":"https://github.com/beyondcode/laravel-fixed-window-limiter","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/beyondcode/laravel-fixed-window-limiter","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beyondcode%2Flaravel-fixed-window-limiter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beyondcode%2Flaravel-fixed-window-limiter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beyondcode%2Flaravel-fixed-window-limiter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beyondcode%2Flaravel-fixed-window-limiter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/beyondcode","download_url":"https://codeload.github.com/beyondcode/laravel-fixed-window-limiter/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beyondcode%2Flaravel-fixed-window-limiter/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264406095,"owners_count":23603062,"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-08-04T09:02:40.680Z","updated_at":"2025-07-09T06:31:32.180Z","avatar_url":"https://github.com/beyondcode.png","language":"PHP","readme":"# Fixed Time Window Rate Limiter for Laravel\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/beyondcode/laravel-fixed-window-limiter.svg?style=flat-square)](https://packagist.org/packages/beyondcode/laravel-fixed-window-limiter)\n[![Build Status](https://img.shields.io/travis/beyondcode/laravel-fixed-window-limiter/master.svg?style=flat-square)](https://travis-ci.org/beyondcode/laravel-fixed-window-limiter)\n[![Quality Score](https://img.shields.io/scrutinizer/g/beyondcode/laravel-fixed-window-limiter.svg?style=flat-square)](https://scrutinizer-ci.com/g/beyondcode/laravel-fixed-window-limiter)\n[![Total Downloads](https://img.shields.io/packagist/dt/beyondcode/laravel-fixed-window-limiter.svg?style=flat-square)](https://packagist.org/packages/beyondcode/laravel-fixed-window-limiter)\n\nThis package allows you to easily create and validate rate limiting using the fixed window algorithm.\n\nThis package makes use of  Redis' atomic requests.\n\n![](https://beyondco.de/github/limiter/limiter.png)\n\n## Installation\n\nYou can install the package via composer:\n\n```bash\ncomposer require beyondcode/laravel-fixed-window-limiter\n```\n\n## Usage\n\nYou can create a new limiter instance by calling the `create` method and pass it a CarbonInterval that represents the window of time, that will be used for the limiter.\nThe second argument is the maximum number of requests/attempts that your limiter will accept in that given time frame. \n\n``` php\n$limiter = FixedWindowLimiter::create(CarbonInterval::second(2), 2);\n```\n\n### Running attempts against your limiter\n\nOnce your limiter is created, you can perform attempts against it to see if the call is within the usage limits that you specified.\nSince your limiter can be used for multiple resources, you need to pass the resource that you want to attempt the call for in the `attempt` method call.\n\n```php\n$limiter-\u003eattempt('user_1');\n```\n\n### Getting the usage count\n\nWhen you want to read the number of attempts that were made for a given resource, you may call the `getUsage` method.\n\n**Note:** This method will not return the number of attempts, but only the number of successful attempts. Use the `getRealUsage` method, if you want to see all attempts, including those that were rejected.\n\n```php\n$count = $limiter-\u003egetUsage('user_1');\n```\n\nOr as mentioned, to get the real usage of all attempts for the resource:\n\n```php\n$count = $limiter-\u003egetRealUsage('user_1');\n```\n\n### Reset the limiter\n\nIf you want to reset the attempts for a specific resource, you may call the `reset` method on the limiter instance. This will reset the TTL to the given time frame and re-allow new attempts.\n\n```php\n$limiter-\u003ereset('user_1');\n```\n\n### Additional data\n\nSometimes you might want to store additional data inside of the resource hash in Redis. You can pass the initial data to the `reset` method.\n\n```php\n$limiter-\u003ereset('user_1', [\n    'key' =\u003e 'value'\n]);\n```\n\nIn order to retrieve the data, you may use the `getAdditionalData` method.\n\n```php\n$value = $limiter-\u003egetAdditionalData('user_1', 'key');\n```\n\n### Testing\n\n``` bash\ncomposer test\n```\n\n### Changelog\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.\n\n## Contributing\n\nPlease see [CONTRIBUTING](CONTRIBUTING.md) for details.\n\n### Security\n\nIf you discover any security related issues, please email marcel@beyondco.de instead of using the issue tracker.\n\n## Credits\n\n- [Marcel Pociot](https://github.com/mpociot)\n- [All Contributors](../../contributors)\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n","funding_links":[],"categories":["PHP"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbeyondcode%2Flaravel-fixed-window-limiter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbeyondcode%2Flaravel-fixed-window-limiter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbeyondcode%2Flaravel-fixed-window-limiter/lists"}