public function consume($tokens)
    {
        $timedOut = is_null($this->timeout) ? null : (microtime(true) + $this->timeout);
        while (!$this->bucket->consume($tokens, $seconds)) {
            self::throwTimeoutIfExceeded($timedOut);
            $seconds = self::keepSecondsWithinTimeout($seconds, $timedOut);
            
            // avoid an overflow before converting $seconds into microseconds.
            if ($seconds > 1) {
                // leave more than one second to avoid sleeping the minimum of one millisecond.
                $sleepSeconds = ((int) $seconds) - 1;

                sleep($sleepSeconds);
                $seconds -= $sleepSeconds;
            }

            // sleep at least 1 millisecond.
            usleep(max(1000, $seconds * 1000000));
        }
    }
public function consume($tokens)
    {
        $timedOut = is_null($this->timeout) ? null : (microtime(true) + $this->timeout);
        while (!$this->bucket->consume($tokens, $seconds)) {
            self::throwTimeoutIfExceeded($timedOut);
            $seconds = self::keepSecondsWithinTimeout($seconds, $timedOut);
            
            // avoid an overflow before converting $seconds into microseconds.
            if ($seconds > 1) {
                // leave more than one second to avoid sleeping the minimum of one millisecond.
                $sleepSeconds = ((int) $seconds) - 1;

                sleep($sleepSeconds);
                $seconds -= $sleepSeconds;
            }

            // sleep at least 1 millisecond.
            usleep(max(1000, $seconds * 1000000));
        }
    }
public function consume ( $ tokens ) { $ timedOut = is_null ( $ this -> timeout ) ? null : ( microtime ( true ) + $ this -> timeout ) ; while ( ! $ this -> bucket -> consume ( $ tokens , $ seconds ) ) { self :: throwTimeoutIfExceeded ( $ timedOut ) ; $ seconds = self :: keepSecondsWithinTimeout ( $ seconds , $ timedOut ) ; // avoid an overflow before converting $seconds into microseconds. if ( $ seconds > 1 ) { // leave more than one second to avoid sleeping the minimum of one millisecond. $ sleepSeconds = ( ( int ) $ seconds ) - 1 ; sleep ( $ sleepSeconds ) ; $ seconds -= $ sleepSeconds ; } // sleep at least 1 millisecond. usleep ( max ( 1000 , $ seconds * 1000000 ) ) ; } }
Consumes tokens.

If the underlying token bucket doesn't have sufficient tokens, the
consumer blocks until it can consume the tokens.

@param int $tokens The token amount.

@throws \LengthException The token amount is larger than the bucket's capacity.
@throws StorageException The stored microtime could not be accessed.
@throws TimeoutException The timeout was exceeded.
Consumes tokens .