Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to configure the HttpClient maximumBackoffDuration #33

Merged
merged 1 commit into from
Mar 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
eexit marked this conversation as resolved.
Show resolved Hide resolved
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