Official PHP API Client for FeatureSwitches

v0.8.6 2016-04-01 01:34 UTC

This package is not auto-updated.

Last update: 2021-01-22 23:15:45 UTC


A PHP client library for interacting with FeatureSwitches.com. This library is under active development and is likely to change frequently. Bug reports and pull requests are welcome.


Install with Composer

php composer.phar require featureswitches/featureswitches-php


require 'vendor/autoload.php';

// Create a new FSClient with your customer and environment API key's
$featureswitches = new FeatureSwitches\FSClient('customer_api_key', 'environment_api_key', array('options'));

// Ensure that the API credentials are valid
$result = $featureswitches->authenticate();  # result will be true/false to indicate success

// Sync feature state

// Add a user
$result = $featureswitches->addUser('user_identifier', 'optional_customer_identifier', 'optional_name', 'optional_email');

// Check if a feature is enabled
$result = $featureswitches->isEnabled('feature_key', 'optional_user_identifier', default(true/false, default=false));

if ($result == true) {
    // Feature enabled, do something
} else {
    // Feature disabled, do something else

Configuration Options

The library locally caches responses from the FeatureSwitches API to cut down on response time and repeat requests. The default cache timeout is 300 seconds (5 minutes). You can adjust the cache timeout by providing the 'cache_timeout' config option when initializing the library.

    'cache_timeout' => SECONDS, // optional, defaults to 300 seconds


Bug reports and pull requests are welcome on GitHub at https://github.com/featureswitches/featureswitches-php.


The library is available as open source under the terms of the MIT License.