Skip to content

Commit ca64c65

Browse files
yll1024335892hongweipeng
authored andcommitted
fix: Implicit conversion from float to int loses precision
1 parent 26b73d8 commit ca64c65

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/throttle/TokenBucket.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ public function allowRequest(string $key, float $micronow, int $max_requests, in
3333

3434
if ($token_left < 1) {
3535
$tmp = (int) ceil($duration / $max_requests);
36-
$this->wait_seconds = $tmp - ($micronow - $last_time) % $tmp;
36+
$this->wait_seconds = $tmp - intval(($micronow - $last_time)) % $tmp;
3737
return false;
3838
}
3939
$this->cur_requests = $max_requests - $token_left;
4040
$cache->set($key, $micronow, $duration);
4141
$cache->set($assist_key, $token_left - 1, $duration);
4242
return true;
4343
}
44-
}
44+
}

0 commit comments

Comments
 (0)