Created
September 4, 2023 20:27
-
-
Save Sammyjo20/2c41434cf3409685ac792ca253725128 to your computer and use it in GitHub Desktop.
Saloon Custom Rate Limit Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Saloon\RateLimitPlugin\Limit; | |
use Saloon\Http\Response; | |
Limit::custom(function (Response $response, Limit $limit) { | |
$hasExceededLimit = (int)$response->header('x-ratelimit-remaining-requests') === 0; | |
if ($hasExceededLimit === true) { | |
$limit->exceeded($releaseInSeconds); | |
} | |
})->name('some-name-unique-by-' . $userId); | |
// Tokens | |
Limit::custom(function (Response $response, Limit $limit) { | |
$hasExceededLimit = (int)$response->header('x-ratelimit-remaining-tokens') === 0; | |
if ($hasExceededLimit === true) { | |
$limit->exceeded($releaseInSeconds); | |
} | |
})->name('some-name-unique-by-' . $userId); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment