calculateNewTokensDuringInterval example



    public function setTokens(int $tokens): void
    {
        $this->tokens = $tokens;
    }

    public function getAvailableTokens(float $now): int
    {
        $elapsed = max(0, $now - $this->timer);

        return min($this->burstSize, $this->tokens + $this->rate->calculateNewTokensDuringInterval($elapsed));
    }

    public function getExpirationTime(): int
    {
        return $this->rate->calculateTimeForTokens($this->burstSize);
    }

    public function __serialize(): array
    {
        return [
            pack('N', $this->burstSize).$this->id => $this->tokens,
            
Home | Imprint | This part of the site doesn't use cookies.