flagr/sdk

PHP SDK for flagr.dev — evaluate feature flags via direct API call

Maintainers

Package info

github.com/flagr-dev/sdk-php

pkg:composer/flagr/sdk

Statistics

Installs: 3

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v0.2.0 2026-03-22 15:13 UTC

This package is auto-updated.

Last update: 2026-03-22 15:19:12 UTC


README

PHP SDK for flagr.dev — evaluate feature flags with a direct API call. No dependencies beyond ext-curl and ext-json.

Install

composer require flagr/sdk

Requires PHP 8.1+, ext-curl, ext-json.

Quick start

use Flagr\FlagrClient;

$flagr = new FlagrClient(sdkKey: $_ENV['FLAGR_ENV_KEY']);

if ($flagr->isEnabled('new-checkout', tenantId: $userId)) {
    // show new checkout
}

Usage

isEnabled

$enabled = $flagr->isEnabled(
    flagKey:  'new-checkout',
    tenantId: $userId,   // optional, default "" — omit for flags that don't use partial rollout
    default:  false,     // returned if flag is unknown or request fails
);

tenantId is optional. For partially_enabled flags, an empty tenantId always returns false.

Every call makes a single HTTP POST to /evaluate. No local cache, no background connection.

Flag states

State isEnabled result
enabled true for every tenant
disabled false for every tenant
partially_enabled true only if the tenant ID is in the enabled list

Exceptions

Exception When
Flagr\AuthenticationException SDK key rejected (HTTP 401)
Flagr\EvaluationException Network error or unexpected HTTP status

Lifecycle

The FlagrClient reuses a single cURL handle across calls — instantiate once and reuse within a request. The handle is closed automatically on destruction.