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

Chore: Add an example for http timeout #221

Merged
merged 2 commits into from
Jul 25, 2024
Merged
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
37 changes: 37 additions & 0 deletions examples/10-timeout.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

use GuzzleHttp\Client;
use GuzzleHttp\RequestOptions;
use Symfony\Component\HttpClient\HttpClient;
use Symfony\Component\HttpClient\Psr18Client;
use Unleash\Client\UnleashBuilder;

require __DIR__ . '/_common.php';

if (class_exists(Client::class)) {
$httpClient = new Client([
RequestOptions::TIMEOUT => 2,
]);
} else if (class_exists(Psr18Client::class)) {
$httpClient = HttpClient::create([
'timeout' => 2,
]);
$httpClient = new Psr18Client($httpClient);
} else {
throw new LogicException('No supported http client (for this example) found');
}

$unleash = UnleashBuilder::create()
->withAppName($appName)
->withAppUrl($appUrl)
->withInstanceId($instanceId)
->withHttpClient($httpClient)
->withHeader('Authorization', $apiKey)
->build()
;

if ($unleash->isEnabled('myFeature')) {
echo "myFeature is enabled";
} else {
echo "myFeature is disabled";
}
Loading