-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Chore: Add an example for http timeout (#221)
- Loading branch information
1 parent
e9b6d60
commit e10aed9
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
} |