Documentation Index
Fetch the complete documentation index at: https://launchdarkly-preview.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
Overview
This topic documents how to get started with the PHP SDK, and links to reference information on all of the supported features.LaunchDarkly’s SDKs are open source. In addition to this reference guide, we provide source, API reference documentation, and a sample application:
| Resource | Location |
|---|---|
| SDK API documentation | SDK API docs |
| Supported SDK Versions | PHP SDK |
| GitHub repository | php-server-sdk |
| Sample application | PHP , OpenFeature PHP |
| Published module | Packagist |
Get started
After you complete the Getting Started process, follow these instructions to start using the LaunchDarkly SDK in your PHP application.Understand version compatibility
The LaunchDarkly PHP SDK, version 6.x and higher, is compatible with PHP 8.1 and higher. Starting with version 6.6, the LaunchDarkly PHP SDK also requires that theapcu extension is installed and enabled. The SDK uses the APCu cache to help improve performance.
If you are using older versions:
- The LaunchDarkly PHP SDK, version 5.x, is compatible with PHP 8.0 and higher.
- The LaunchDarkly PHP SDK, version 4.x, is compatible with PHP 7.3 and higher.
- If you need compatibility with older versions of PHP, use version 3.x of the LaunchDarkly PHP SDK.
Install the SDK
The first step is to install Composer and the LaunchDarkly SDK as a dependency in your application. Refer to the SDK releases page to identify the latest version if you want to depend on a specific version. To install Composer:The PHP SDK 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.
Initialize the client
After you install and import the SDK, create a single, shared instance ofLDClient. Specify your SDK key here to authorize your application to connect to a particular environment within LaunchDarkly.
Only create one instance of client.
Here’s how:
LDClient constructor.
Evaluate a context
You can use$client to check which variation a particular context will receive for a given feature flag.
Here’s how:
Fetch flags
There are two distinct methods of integrating LaunchDarkly in a PHP environment:- The Relay Proxy retrieves and stores flags in Redis, DynamoDB, or Consul. This is the recommended method. If you use synced segments or larger list-based segments, you can only use Redis or DynamoDB as a persistent store.
- Guzzle Cache Middleware requests and caches HTTP responses in an in-memory array. This is the default method.
Using the Relay Proxy
PHP’s shared-nothing architecture prevents LaunchDarkly from reusing the streaming API connection across requests. You can use PHP without the Relay Proxy, but we strongly recommend using the Relay Proxy in daemon mode if you are using PHP in a high-throughput setting. This makes the Relay Proxy receive feature flag updates. To learn more, read Configuring SDKs to use different modes.Using Guzzle
For the latest major version of the PHP SDK, use open-ended dependencies. For older versions, refer to your version’s composer.json file. To require Guzzle as a dependency:Supported features
This SDK supports the following features:- Anonymous contexts and users
- Big segments
- Configuration, including
- Context configuration
- Evaluating flags
- Flag evaluation reasons
- Flushing events
- Getting all flags
- Identifying and changing contexts
- Logging configuration
- Migrations
- Offline mode
- Private attributes
- Reading flags from a file
- Relay Proxy configuration
- Secure mode
- Sending custom events
- Storing data
- Test data sources