Browse documentation
Markdown

PHP quickstart

Use the Dipswitch provider with the OpenFeature PHP SDK, PHP 8.2 or later in the 8.x series, and the cURL extension. To install before registry publication, copy the supplied provider directory next to your application at the relative path shown below. Run these commands beside your application’s composer.json.

Terminal
composer config repositories.dipswitch path ../packages/openfeature-php
composer require dipswitch/openfeature-provider:@dev

Set DIPSWITCH_SERVER_KEY in the service environment. Set DIPSWITCH_EDGE_URL to your local edge address when self-hosting. Save this as example.php beside your application's vendor directory. Run php example.php, optionally followed by a user ID and a flag key.

PHP
<?php
require __DIR__ . '/vendor/autoload.php';

use Dipswitch\OpenFeature\DipswitchProvider;
use OpenFeature\implementation\flags\EvaluationContext;
use OpenFeature\OpenFeatureAPI;

$api = OpenFeatureAPI::getInstance();
$api->setProvider(new DipswitchProvider(
    getenv('DIPSWITCH_SERVER_KEY') ?: throw new RuntimeException('Set DIPSWITCH_SERVER_KEY.'),
    getenv('DIPSWITCH_EDGE_URL') ?: 'https://edge.dipswitch.co'
));

$user = new EvaluationContext($argv[1] ?? 'user-42');
$flag = $argv[2] ?? 'new-checkout';
$result = $api->getClient()->getBooleanDetails($flag, false, $user);
printf("%s %s\n", $result->getValue() ? 'true' : 'false', $result->getReason());

Each boolean check asks edge over HTTP. Omit the context for an anonymous user. Choose the fallback boolean for your feature. Use evaluation details to distinguish a missing flag, an invalid context or a failed request from an evaluated value.