Quantcast
Channel: Active questions tagged rest - Stack Overflow
Viewing all articles
Browse latest Browse all 4089

Token Bucket | Fatal Error: The string is not 64 bit long. PHP 8.2 | Api Rate Limit

$
0
0

Trying to use Token Bucket

Fatal error: Uncaught bandwidthThrottle\tokenBucket\storage\StorageException:
The string is not 64 bit long. in \bandwidth-throttle\token-bucket\classes\util\DoublePacker.php: 41

Having this error when applied following code in constructor of ApiController, and tried to use consume:

function __construct() { $this->storage = new FileStorage(__DIR__ . "/api.bucket"); $this->rate    = new Rate(10, Rate::SECOND); $this->bucket  = new TokenBucket(10, $this->rate, $this->storage); //Following code executed once, then commented //$this->bucket->bootstrap(10);}

Checking Rate limit

protected function checkRateLimit() {  if (!$this->bucket->consume(1, $seconds)) {    http_response_code(429);    header(sprintf("Retry-After: %d", floor($seconds)));    exit();   } //echo "Continue to API response"; return true;}

I have also noticed FileStorage class is sending blank string to unpack( ) function in Double Packer on line 129.

bandwidthThrottle\tokenBucket\util\DoublePacker: :unpack('')

Please guide what's going wrong here?


Viewing all articles
Browse latest Browse all 4089

Trending Articles