Skip to content

Conversation

@Crovitche-1623
Copy link
Contributor

@Crovitche-1623 Crovitche-1623 commented Oct 22, 2025

Q A
Branch? 7.4
Bug fix? no
New feature? yes
Deprecations? no
Issues
License MIT

I was looking to rate limit an API that I proxy to another. However, the pricing for the API I am calling is based on a calendar quota (we receive the bill at the end of the month).

On Symfony, I saw that there was a fixed_window policy, which corresponds to a counter for a given interval.

However, the counter seems to start when the request is made, not on a calendar basis.

I could reset the cache used by the rate_limiter at the beginning of the month to make sure it's correct, but that seemed a bit messy.

That's why I propose this CalendarWindowLimiter that can rate limit based on the given CalendarInterval enum value.

The usage would be something like that :

# config/packages/rate_limiter.yaml
framework:
    rate_limiter:
        a_gafam_api_that_gives_a_free_quota:
            policy: calendar_window

            limit: 10000

            calendar_interval: month

@Crovitche-1623
Copy link
Contributor Author

Crovitche-1623 commented Oct 24, 2025

@stof The CI seems to fail because the Psr\Clock\ClockInterface interface is not found in a test. The other limiters were not developed using PSR-20 ClockInterface but regular time() functions and mocked using the ClockMock offered by the PhpUnit Bridge.

What should I do in this case? Rewrite the code using regular time() functions or require the psr/clock at least in --dev for testing?

@Crovitche-1623 Crovitche-1623 requested a review from stof October 24, 2025 08:05
@stof
Copy link
Member

stof commented Oct 24, 2025

you need to add a dev requirement for that optional dependency.

@Crovitche-1623
Copy link
Contributor Author

you need to add a dev requirement for that optional dependency.

Are we sure it's not just a regular dependency, since it's now used in CalendarWindowLimiter.php?

@stof
Copy link
Member

stof commented Oct 24, 2025

the clock is optional in that limiter.

@Crovitche-1623
Copy link
Contributor Author

Everything seems fine on my end 😁. The tests that crashed in CI don't seem to be related to my code.

@nicolas-grekas nicolas-grekas modified the milestones: 7.4, 8.1 Nov 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants