configcat/configcat-client
ConfigCat PHP SDK client for feature flags and remote configuration. Fetch typed setting values from ConfigCat using your SDK key, with targeting by user attributes (region, email, custom). Supports PHP 8.1+ and integrates via Composer.
ConfigCatClient as a singleton in Laravel’s container.onConfigChanged hooks (e.g., trigger cache invalidation).Guzzle, Symfony HttpClient).getError → getErrorMessage). Mitigation: Pin to a stable version (e.g., 9.2.1) and monitor deprecations.forceRefresh() may be needed for real-time updates (though webhook-based polling is supported).auth.v2.enable)?email, region) be used for segmentation? If so, how will they be sourced (e.g., from Laravel’s auth system)?log() channel vs. ConfigCat’s dashboard)?ConfigCatClient as a singleton with lazy initialization.FeatureFlagMiddleware).ConfigCat\Events\FlagUpdated) when flags change.Mockery) to isolate flag logic in unit tests.setOffline() mode enables deterministic testing without network calls.features.new_dashboard) to toggle visibility.User::withEmail($user->email)).HttpClient).ClientOptions::CACHE config.Log facade or PSR-3 loggers.composer require configcat/configcat-client.config/services.php:
'configcat' => [
'sdk_key' => env('CONFIGCAT_SDK_KEY'),
'cache' => 'redis', // Laravel cache driver
'offline' => env('APP_DEBUG'), // Fallback to cache in dev
],
$this->app->singleton(ConfigCatClient::class, function ($app) {
return new ConfigCatClient(
config('services.configcat.sdk_key'),
[
ClientOptions::CACHE => new LaravelCacheAdapter($app['cache']),
]
);
});
ConfigCatClient into controllers/services:
public function __construct(private ConfigCatClient $configCat) {}
$isFeatureEnabled = $this->configCat->getValue('features.new_dashboard', false);
composer.json to pin the SDK version (e.g., ^9.2).LogLevel::DEBUG) in staging for troubleshooting.getValueDetails() to inspect evaluation reasons (e.g., why a user was excluded).Down command).ClientOptions::CACHE with a fast backend (e.g., Redis).getAllValues() to fetch multiple flags in one request.ConfigCatClient only when needed (e.g., in a feature module).| Failure Scenario | Impact | Mitigation |
|---|---|---|
| ConfigCat API downtime | Flags return cached/offline values | Enable offline mode; use local JSON fallback. |
| Cache miss storm | High latency for first requests | Pre-warm cache; use longer TTLs (e.g., 5 minutes). |
| SDK version mismatch | Breaking changes in flag evaluation | Pin to a stable SDK version; test upgrades in staging. |
| Flag key typos | Silent failures (default |
How can I help you explore Laravel packages today?