Getting started with PHP SDK

2 minute read

This section describes how to set up and install the PHP SDK and how to deploy a feature flag.

Step 1 - Setting up

The following are prerequisites for installing the PHP SDK:

  1. Create a CloudBees Feature Management account. See Signup Page to create an account.

  2. Get your environment key. Copy your environment key from App settings > Environments > Key.

Step 2 - Installing the PHP SDK

Add the CloudBees Feature Management PHP package to your application.

composer require rollout/rox

Add the following lines of code to your application:

<?php use Rox\Server\Rox; use Rox\Server\Flags\RoxDouble; use Rox\Server\Flags\RoxFlag; use Rox\Server\Flags\RoxInt; use Rox\Server\Flags\RoxString; require __DIR__ . '/vendor/autoload.php'; class Container { public $enableTutorial; public $titleColors; public $titleSize; public $specialNumber; public function __construct() { $this->enableTutorial = new RoxFlag(false); $this->titleColors = new RoxString("red", ["blue", "green"]); $this->titleSize = new RoxInt(12, [14, 18]); $this->specialNumber = new RoxDouble(3.14, [2.71, 0.577]); } } $container = new Container(); Rox::register($container); Rox::setup("<ROLLOUT_ENV_KEY>"); # Boolean flag example echo "enableTutorial is " . ($container->enableTutorial->isEnabled() ? "true" : "false"); # String flag example echo "color is " . $container->titleColors->getValue(); # Integer flag example echo "title size is " . $container->titleSize->getValue(); # Double flag example echo "special number is " . $container->specialNumber->getValue(); ?>

Run your application

Running the application

The flag name is automatically added to the CloudBees Feature Management dashboard after running the application.

Step 3 - Deploying a feature flag

Finding your flags in the CloudBees Feature Management dashboard

After creating feature flags and running your feature code, you can find your flags in the CloudBees Feature Management dashboard.

To find your flags in the dashboard:

  1. Find your application in the CloudBees Feature Management dashboard. To switch between apps, click on the app name in the top-left corner of the screen and select the app you want from the pulldown.

  2. Click on Flags on the left side of the navigation panel.

  3. Confirm that your flag is listed in the flag view.

Configuring deployment rules

Refer to Configuring flags for release to configure your deployment rules.

  • You cannot delete the default condition.

  • You can click the Reset link to go back to the state from before you started making changes. Reset only appears when you’ve made saved modifications.