Skip to main content

PHP SDK

Segment membership​

Create the list in the dashboard and attach it to a Targeting filter. Sync members with a Backend application key. Evaluation uses the published list after the next definitions refresh. Flow · HTTP API

Server only

Requires a Backend application key. Do not call this from a browser, mobile app, or other public client.

$segments = new Toggly\FeatureManagement\SegmentMembershipClient(
$httpClient,
$requestFactory,
$streamFactory,
getenv('TOGGLY_APP_KEY')
);
$segments->addSegmentMembers('Beta Testers', ['user-123']);
$segments->removeSegmentMembers('Beta Testers', ['user-123']);
$segments->replaceSegmentMembers('Beta Testers', ['user-123']);

Use feature flags in plain PHP, Laravel and WordPress. The core package loads flag definitions and evaluates them; the framework packages add native routing, view and plugin integration. Laravel and WordPress include core as a dependency.

Quick reference

Choose your starting point​

ApplicationInstallNext step
Plain PHP / custom frameworkcomposer require toggly/feature-management-php guzzlehttp/guzzle guzzlehttp/psr7Complete first-flag entry point
Laravelcomposer require toggly/laravel guzzlehttp/guzzle guzzlehttp/psr7HTTP bindings, refresh and native views
WordPresscomposer require toggly/wordpressAutoload, plugin activation and cron

The examples use PHP 8 syntax. The packages retain a PHP 7.4 declared floor and support PHP through 8.5. PHP 8.5 is the current tested runtime. Laravel 8.0 or newer remains supported; current packed-package checks cover Laravel 10.3.3, 11.6.1, 12.12.2, and 13.10.1. The WordPress plugin retains WordPress 5.0+ support and is currently validated on WordPress 7.1 with PHP 8.5. Use composer check-platform-reqs for your installed combination. A declared floor does not by itself prove every earlier host version still runs.

Understand the first decision​

  1. Create an app and environment in Toggly, then a flag such as new-dashboard.
  2. Supply your app key through host configuration and initialize the SDK.
  3. Refresh definitions before the first check when no usable snapshot exists.
  4. Evaluate the flag and keep an explicit disabled branch.
  5. Schedule future refreshes and flush telemetry in the process that collects it.

refresh_interval alone does not start polling. Definitions can be persisted in an explicitly selected snapshot provider; core has no default snapshot storage.

After Laravel host setup, a controller can use:

use Toggly\Laravel\Facades\Toggly;

$context = ['identity' => auth()->check() ? (string) auth()->id() : null];
if (Toggly::isEnabled('new-dashboard', $context)) {
return view('dashboard.new');
}
return view('dashboard.original');

Blade conditions and components are registered by the package. Route gates and PHP attributes require the middleware registration in the Laravel guide. For WordPress, the helper is the global function toggly_is_enabled; it becomes available after plugin initialization. See the native host guide before adding a helper or shortcode to your theme.

User context and variants​

Ordinary FeatureManager::isEnabled($key, $context) accepts a per-evaluation array. Prefer identity, groups, claims and request; userId / user_id remain identity fallbacks. The telemetry context provider does not inject these values into ordinary evaluations.

Variants use a different path: enable enable_variants, supply the provider's initial identity, construct it and refresh. Read FeatureProvider::getVariant($key) for {name, configurationValue} or null. There is no per-call context argument on getVariant. Isolate providers by identity instead of mutating a shared provider while serving users.

PHP does not implement ContextProperty, entity registration or per-call entity objects. An Order or traits array does not add an entity filter. Read the filter matrix and entity context product model with this SDK boundary in mind.

Next steps​