Skip to content

Commit daa5bac

Browse files
authored
解决类型转换出现的问题 (#15)
1 parent c63afa6 commit daa5bac

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

src/throttle/CounterFixed.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class CounterFixed extends ThrottleAbstract
1515

1616
public function allowRequest(string $key, float $micronow, int $max_requests, int $duration, CacheInterface $cache): bool
1717
{
18-
$cur_requests = $cache->get($key, 0);
18+
$cur_requests = (int) $cache->get($key, 0);
1919
$now = (int) $micronow;
2020
$wait_reset_seconds = $duration - $now % $duration; // 距离下次重置还有n秒时间
2121
$this->wait_seconds = $wait_reset_seconds % $duration + 1;

src/throttle/LeakyBucket.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public function allowRequest(string $key, float $micronow, int $max_requests, in
1717
{
1818
if ($max_requests <= 0) return false;
1919

20-
$last_time = $cache->get($key, 0); // 最近一次请求
20+
$last_time = (float) $cache->get($key, 0); // 最近一次请求
2121
$rate = (float) $duration / $max_requests; // 平均 n 秒一个请求
2222
if ($micronow - $last_time < $rate) {
2323
$this->cur_requests = 1;

src/throttle/ThrottleAbstract.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ abstract public function allowRequest(string $key, float $micronow, int $max_req
3030
*/
3131
public function getWaitSeconds(): int
3232
{
33-
return $this->wait_seconds;
33+
return (int) $this->wait_seconds;
3434
}
3535

3636
/**
@@ -39,7 +39,7 @@ public function getWaitSeconds(): int
3939
*/
4040
public function getCurRequests(): int
4141
{
42-
return $this->cur_requests;
42+
return (int) $this->cur_requests;
4343
}
4444

4545
}

0 commit comments

Comments
 (0)