Skip to content

Commit

Permalink
Allow to configure the HttpClient maximumBackoffDuration
Browse files Browse the repository at this point in the history
  • Loading branch information
Joris Berthelot committed May 20, 2022
1 parent 2d42699 commit 961baf9
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function __construct(string $apiKey, array $options = [], ?HttpClient $ht
$this->httpClient = $httpClient !== null ? $httpClient : new HttpClient(
$options['host'] ?? "app.posthog.com",
$options['ssl'] ?? true,
10000,
(int) ($options['maximum_backoff_duration'] ?? 10000),
false,
$options["debug"] ?? false
);
Expand Down
6 changes: 3 additions & 3 deletions lib/HttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ public function sendRequest(string $path, ?string $payload, array $extraHeaders
{
$protocol = $this->useSsl ? "https://" : "http://";

$backoff = 100; // Set initial waiting time to 100ms
$backoff = 100; // Set initial waiting time to 100ms

while ($backoff < $this->maximumBackoffDuration) {
do {
// open connection
$ch = curl_init();

Expand Down Expand Up @@ -115,7 +115,7 @@ public function sendRequest(string $path, ?string $payload, array $extraHeaders
} else {
break; // no error
}
}
} while ($backoff < $this->maximumBackoffDuration);

return $httpResponse;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/PostHog.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class PostHog
{
public const VERSION = '2.1.0';
public const VERSION = '2.1.1';
public const ENV_API_KEY = "POSTHOG_API_KEY";
public const ENV_HOST = "POSTHOG_HOST";

Expand Down
4 changes: 4 additions & 0 deletions lib/QueueConsumer.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ public function __construct($apiKey, $options = array())
$this->batch_size = $options["batch_size"];
}

if (isset($options["maximum_backoff_duration"])) {
$this->maximum_backoff_duration = (int) $options["maximum_backoff_duration"];
}

if (isset($options["host"])) {
$this->host = $options["host"];

Expand Down

0 comments on commit 961baf9

Please sign in to comment.