PHP SDK installation

2 minute read

Control feature rollout for certain user segments of your application with feature flags. To start using feature management in the platform, follow the instructions below to install the SDK and deploy a feature flag.

Install the SDK

Follow these steps to install the SDK:

  1. Select Feature management  Installation.

  2. Select an Environment from the options, or create an environment by completing the following:

    1. Select CREATE ENVIRONMENT.

    2. Enter an Environment name.

    3. (Optional) Enter a Description.

    4. (Optional) Select Approvers if you want to have a manual approval required before deployment.

    5. (Optional) Enter any Properties you want to associate with the environment. For more information, refer to properties configuration and properties in an environment.

    6. Select SUBMIT.

  3. Select PHP from the language options.

  4. Select a package manager from the options.

Install the ROX package in PHP

Add the ROX package to your application by running the shell command appropriate for your package manager, listed in the following table:

Table 1. Commands to add the ROX package to your application
Package manager Project Commands to run

Composer

PHP

composer require rox/server

Import the SDK and set up feature flags

Add the following code to your PHP application:

<?php require 'vendor/autoload.php'; use Rox\Server\Rox; use Rox\Server\Flags\RoxFlag; use Rox\Server\Flags\RoxString; use Rox\Server\Flags\RoxInt; // Define your SDK key (Replace <YOUR-SDK-KEY> with your actual key) define('DEFAULT_API_KEY', '<YOUR-SDK-KEY>'); (1) // Define feature flags class FeatureFlags { public $enableTutorial; public $titleColors; public $titleSize; public function __construct() { $this->enableTutorial = new RoxFlag(); $this->titleColors = new RoxString("White", ["White", "Blue", "Green", "Yellow"]); $this->titleSize = new RoxInt(12, [14, 18, 24]); } } // Initialize feature flags $flags = new FeatureFlags(); // Register feature flags Rox::register("", $flags); // Setup connection with the feature management environment key Rox::setup(DEFAULT_API_KEY); // Boolean flag example if ($flags->enableTutorial->isEnabled()) { echo "enableTutorial flag is true\n"; // TODO: Add code here that needs to be gated } // RoxString flag example echo "Title color is " . $flags->titleColors->getValue() . "\n"; // RoxInt flag example echo "Title size is " . $flags->titleSize->getValue() . "\n"; echo "Done loading CloudBees platform\n"; ?>
1 The platform provides the unique SDK key for your environment at the <YOUR-SDK-KEY> location within the Rox.setup call.

Run the application and test the integration

Follow these steps to test the integration:

  1. Run your application.

  2. In the CloudBees platform, select TEST INTEGRATION to verify the SDK connection.

After running the application, flags added in the code are automatically added to your feature flag list.

You have installed an SDK and created flags in your application.

Refer to the SDK reference for more information.

Next steps

  • Use feature flags to control application behavior dynamically.

  • Define custom properties for targeted rollouts.

  • Integrate with CloudBees platform workflows to automate feature deployments.