public static function willTakeAction($actors, $action, $score)
public static function willTakeAction($actors, $action, $score)
Prepare to take an action, throwing an exception if the user has exceeded the rate limit.
The $actors are a list of strings. Normally this will be a list of user PHIDs, but some systems use other identifiers (like email addresses). Each actor's score threshold is tracked independently. If any actor exceeds the rate limit for the action, this method throws.
The $action defines the actual thing being rate limited, and sets the limit.
You can pass either a positive, zero, or negative $score to this method:
- If the score is positive, the user is given that many points toward the rate limit after the limit is checked. Over time, this will cause them to hit the rate limit and be prevented from taking further actions.
- If the score is zero, the rate limit is checked but no score changes are made. This allows you to check for a rate limit before beginning a workflow, so the user doesn't fill in a form only to get rate limited at the end.
- If the score is negative, the user is credited points, allowing them to take more actions than the limit normally permits. By awarding points for failed actions and credits for successful actions, a system can be sensitive to failure without overly restricting legitimate uses.
If any actor is exceeding their rate limit, this method throws a PhabricatorSystemActionRateLimitException.
Parameters
list<string> | $actors | List of actors. |
PhabricatorSystemAction | $action | Action being taken. |
float | $score | Score or credit, see above. |
Return
void |
public static function loadBlockedActors($actors, $action, $score)
public static function loadBlockedActors($actors, $action, $score)
Parameters
array | $actors | |
PhabricatorSystemAction | $action | |
$score |
Return
wild |
public static function loadScores($actors, $action)
public static function loadScores($actors, $action)
Parameters
array | $actors | |
PhabricatorSystemAction | $action |
Return
wild |
private static function recordAction($actors, $action, $score)
private static function recordAction($actors, $action, $score)
Parameters
array | $actors | |
PhabricatorSystemAction | $action | |
$score |
Return
wild |
private static function getWindow()
private static function getWindow()
Return
wild |
public static function resetActions($actors)
public static function resetActions($actors)
Reset all action counts for actions taken by some set of actors in the previous action window.
Parameters
list<string> | $actors | Actors to reset counts for. |
Return
int | Number of actions cleared. |
public static function newActorFromRequest($request)
public static function newActorFromRequest($request)
Parameters
AphrontRequest | $request |
Return
wild |