1. Go to this page and download the library: Download avsbhq/avsb library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
avsbhq / avsb example snippets
use Avsbhq\Avsb\AvsbServer;
use Avsbhq\Avsb\EvalContext;
$server = new AvsbServer($_ENV['AVSB_SDK_KEY']);
$flag = $server->getBoolFlag('checkout_v2', false, EvalContext::user('alice', [
'plan' => 'pro',
]));
if ($flag->value) {
// serve the new checkout
}
$server->track('checkout_completed', EvalContext::user('alice'), revenue: 49.99);
use Avsbhq\Avsb\AvsbServer;
use Avsbhq\Avsb\AvsbServerOptions;
use Avsbhq\Avsb\Datafile\FileDatafileCache;
$server = new AvsbServer($_ENV['AVSB_SDK_KEY'], new AvsbServerOptions(
logger: $psr3Logger,
cache: new FileDatafileCache('/dev/shm/avsb'),
datafileTtlSeconds: 30,
fetchTimeoutSeconds: 2.0,
stickyBucketService: $redisStickyStore,
));
use Avsbhq\Avsb\Http\Psr18Transport;
$options = new AvsbServerOptions(
transport: new Psr18Transport($psr18Client, $psr17RequestFactory, $psr17StreamFactory),
);
use Avsbhq\Avsb\EvalContext;
$context = EvalContext::user('alice', [
'plan' => 'pro', // targeting attributes, any JSON value
'betaTester' => true,
]);
// Any single kind
$org = EvalContext::user('acme-corp', ['tier' => 'enterprise'], 'organization');
// Several kinds at once
$context = EvalContext::multi([
'user' => ['key' => 'alice', 'plan' => 'pro'],
'organization' => ['key' => 'acme', 'tier' => 'enterprise'],
]);
// Or wrap a decoded array already in the wire shape
$context = EvalContext::fromArray($decoded);
$flag = $server->getBoolFlag('checkout_v2', false, $context);
$flag->value; // mixed the evaluated value
$flag->variationKey; // string|null null for default, not_found, not_ready
$flag->source; // EvaluationSource why this value (enum, see below)
$flag->ruleId; // string|null the rule or holdout that decided
$flag->ruleType; // RuleType|null AbTest, TargetedDelivery, Holdout, Bandit
$flag->reasons; // list<string> the decision trail, in order
$flag->evaluatedAt; // int milliseconds since the Unix epoch
$flag->durationMicros; // int microseconds spent evaluating
$flag->isEnabled(); // bool
$flag->exists(); // bool
use Avsbhq\Avsb\Sticky\RedisStickyBucketService;
$server = new AvsbServer($sdkKey, new AvsbServerOptions(
stickyBucketService: new RedisStickyBucketService($redis),
));
$server = new AvsbServer($sdkKey, new AvsbServerOptions(logger: $monolog));
return [
'sdk_key' => env('AVSB_SDK_KEY', ''),
// Optional: point at a datafile another process keeps fresh (the agent
// shape). When the file exists it wins and the SDK never fetches.
'datafile_path' => env('AVSB_DATAFILE_PATH', ''),
];
public function __construct(private readonly AvsbServer $avsb) {}