> ## Documentation Index
> Fetch the complete documentation index at: https://launchdarkly-preview.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# OpenFeature provider for PHP SDK

> This topic documents how to get started with the LaunchDarkly OpenFeature provider for the PHP SDK.

> For the complete documentation index, see [llms.txt](/llms.txt). For the full documentation snapshot, see [llms-full.txt](/llms-full.txt).

## Overview

This topic documents how to get started with the LaunchDarkly OpenFeature provider for the PHP SDK.

<Note title="Provider quick links">
  LaunchDarkly's OpenFeature providers are open source. In addition to this reference guide, we provide source, API reference documentation, and a sample application:
</Note>

| Resource | Location |
| - | - |
| OpenFeature Provider API documentation | [Provider API docs](https://launchdarkly.github.io/openfeature-php-server/) |
| GitHub repository | [openfeature-php-server](https://github.com/launchdarkly/openfeature-php-server) |
| Sample application | [Sample OpenFeature PHP provider application](https://github.com/launchdarkly/hello-openfeature-php-server) |
| Published module | [Packagist](https://packagist.org/packages/launchdarkly/openfeature-server) |

## Get started

The LaunchDarkly OpenFeature provider for the PHP SDK is intended for use in multi-user systems such as web servers and application. It is not intended for use in desktop and embedded systems applications.

Follow these instructions to start using the LaunchDarkly OpenFeature provider for the PHP SDK in your application.

### Version compatibility

The LaunchDarkly OpenFeature provider for the PHP SDK is compatible with the [OpenFeature PHP SDK v2.x and above](https://openfeature.dev/docs/reference/technologies/server/php).

The provider is compatible with PHP 8.1+.

## Install the provider

First, add the LaunchDarkly OpenFeature package:

<CodeGroup>
  ```bash title="Shell" theme={null}
      composer require launchdarkly/openfeature-server
  ```
</CodeGroup>

Next, import the OpenFeature namespaces in your application code:

<CodeGroup>
  ```php title="LaunchDarkly PHP provider" theme={null}
      use OpenFeature\OpenFeatureAPI;
      use OpenFeature\implementation\flags\Attributes;
      use OpenFeature\implementation\flags\EvaluationContext;
  ```
</CodeGroup>

## Initialize the provider

After you install and import the provider, create a single, shared instance of [`Provider`](https://launchdarkly.github.io/openfeature-php-server/classes/LaunchDarkly-OpenFeature-Provider.html). Specify your SDK key here to authorize your application to connect to a particular environment within LaunchDarkly.

Here's how:

<CodeGroup>
  ```php title="PHP" theme={null}
      $config = [];
      $provider = new LaunchDarkly\OpenFeature\Provider("YOUR_SDK_KEY", $config);
      $api = OpenFeatureAPI::getInstance();
      $api->setProvider($provider);

      $client = $api->getClient("hello-client", 1);
  ```
</CodeGroup>

The configuration options are from the LaunchDarkly PHP SDK. To learn more about the configuration options available, read [Configuration](/sdk/features/config#php).

<Note title="The PHP provider uses an SDK key">
  The LaunchDarkly PHP provider uses an SDK key. Keys are specific to each project and environment. They are available from **Project settings**, on the **Environments** list. To learn more about key types, read [Keys](/sdk/concepts/client-side-server-side#keys).
</Note>

## Construct a context

A [context](/home/getting-started/vocabulary#context) is a generalized way of referring to the people, services, machines, or other resources that encounter feature flags in your product. The OpenFeature specification calls these [evaluation contexts](https://openfeature.dev/docs/reference/concepts/evaluation-context).

In the LaunchDarkly provider, contexts:

* always have a particular [context kind](/home/getting-started/vocabulary#context-kind). If you do not specify a kind, the provider treats the context as having a "user" kind. To specify a different kind, including a multi-context, you must include a `kind` attribute.
* must have a targeting key. This is optional in the OpenFeature specification, but LaunchDarkly requires a key for evaluation. You can specify this using `targetingKey`, as in the OpenFeature specification, or `key`, which is the typical LaunchDarkly identifier for the targeting key.

Here are examples of a context:

<CodeGroup>
  ```php title="Example user context" theme={null}
      $context = new EvaluationContext("example-user-key");
  ```

  ```php title="Example organization context" theme={null}
      $attributes = new Attributes(["kind" => "organization"]);
      $context = new EvaluationContext("example-user-key", $attributes);
  ```
</CodeGroup>

For additional examples, read [OpenFeature specific considerations](https://github.com/launchdarkly/openfeature-php-server?tab=readme-ov-file#openfeature-specific-considerations) in the provider GitHub repository.

## Evaluate a context

To evaluate feature flags for a context, use the OpenFeature [Evaluation API](https://openfeature.dev/docs/reference/concepts/evaluation-api). For example:

<CodeGroup>
  ```php title="Evaluate a context" theme={null}
      $flagValue = $client->getBooleanValue("example-flag-key", false, $context);
  ```
</CodeGroup>
