-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Closed
Description
Symfony version(s) affected
6.2.0
Description
I'm receiving following errors in my application
PHP Deprecation Notice: Implicit conversion from float 59999985.93330383 to int loses precision in /var/www/html/vendor/symfony/rate-limiter/Reservation.php line 48
The usleep function accepts int as parameter type (https://www.php.net/manual/en/function.usleep.php), while the passed type is float in Reservation::wait
(due to Reservation::getWaitDuration
returning a float value for the 1e6 multiplication)
How to reproduce
$limiter = (new RateLimiterFactory(
[
'id' => 'api',
'policy' => 'token_bucket',
'rate' => [
'interval' => '1 minute',
'amount' => 1
],
'limit' => 1,
],
new InMemoryStorage()
))->create('api');
$limiter->reserve()->wait();
$limiter->reserve()->wait();
Possible Solution
type casting the resulting wait time from float to int fixes the problem
usleep((int) ($this->getWaitDuration() * 1e6));
Additional Context
No response
ostrolucky