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?