Skip to content

Commit

Permalink
Chore: Add an example for http timeout (#221)
Browse files Browse the repository at this point in the history
  • Loading branch information
RikudouSage authored Jul 25, 2024
1 parent e9b6d60 commit e10aed9
Showing 1 changed file with 37 additions and 0 deletions.
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";
}

0 comments on commit e10aed9

Please sign in to comment.