Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / support / startup / PhabricatorClientRateLimit.php
blob89a273e3bf28b408a151d412e7c052e44ed56940
1 <?php
3 final class PhabricatorClientRateLimit
4 extends PhabricatorClientLimit {
6 protected function getBucketDuration() {
7 return 60;
10 protected function getBucketCount() {
11 return 5;
14 protected function shouldRejectConnection($score) {
15 $limit = $this->getLimit();
17 // Reject connections if the average score across all buckets exceeds the
18 // limit.
19 $average_score = $score / $this->getBucketCount();
21 return ($average_score > $limit);
24 protected function getConnectScore() {
25 return 0;
28 protected function getPenaltyScore() {
29 return 1;
32 protected function getDisconnectScore(array $request_state) {
33 $score = 1;
35 // If the user was logged in, let them make more requests.
36 if (isset($request_state['viewer'])) {
37 $viewer = $request_state['viewer'];
38 if ($viewer->isOmnipotent()) {
39 // If the viewer was omnipotent, this was an intracluster request or
40 // some other kind of special request, so don't give it any points
41 // toward rate limiting.
42 $score = 0;
43 } else if ($viewer->isLoggedIn()) {
44 // If the viewer was logged in, give them fewer points than if they
45 // were logged out, since this traffic is much more likely to be
46 // legitimate.
47 $score = 0.25;
51 return $score;
54 protected function getRateLimitReason($score) {
55 $client_key = $this->getClientKey();
57 // NOTE: This happens before we load libraries, so we can not use pht()
58 // here.
60 return
61 "TOO MANY REQUESTS\n".
62 "You (\"{$client_key}\") are issuing too many requests ".
63 "too quickly.\n";