|
1 |
| -LaunchDarkly SDK for PHP |
2 |
| -=========================== |
| 1 | +# LaunchDarkly Server-side SDK for PHP |
3 | 2 |
|
4 |
| -[](https://circleci.com/gh/launchdarkly/php-client) |
| 3 | +[](https://circleci.com/gh/launchdarkly/php-server-sdk) |
5 | 4 |
|
6 |
| -Requirements |
7 |
| ------------- |
8 |
| -1. PHP 5.5 or higher. |
| 5 | +## LaunchDarkly overview |
9 | 6 |
|
10 |
| -Quick setup |
11 |
| ------------ |
| 7 | +[LaunchDarkly](https://www.launchdarkly.com) is a feature management platform that serves over 100 billion feature flags daily to help teams build better software, faster. [Get started](https://docs.launchdarkly.com/docs/getting-started) using LaunchDarkly today! |
| 8 | + |
| 9 | +[](https://twitter.com/intent/follow?screen_name=launchdarkly) |
12 | 10 |
|
13 |
| -1. Install the PHP SDK and monolog for logging with [Composer](https://getcomposer.org/) |
| 11 | +## Supported PHP versions |
14 | 12 |
|
15 |
| - php composer.phar require launchdarkly/launchdarkly-php |
| 13 | +This version of the LaunchDarkly SDK is compatible with PHP 5.5 and higher. |
16 | 14 |
|
17 |
| -1. After installing, require Composer's autoloader: |
| 15 | +## Getting started |
18 | 16 |
|
19 |
| - require 'vendor/autoload.php'; |
| 17 | +Refer to the [SDK reference guide](https://docs.launchdarkly.com/docs/php-sdk-reference) for instructions on getting started with using the SDK. |
20 | 18 |
|
21 |
| -1. Create a new LDClient with your SDK key: |
| 19 | +## Learn more |
22 | 20 |
|
23 |
| - $client = new LaunchDarkly\LDClient("your_sdk_key"); |
24 |
| - |
25 |
| -Your first feature flag |
26 |
| ------------------------ |
27 |
| - |
28 |
| -1. Create a new feature flag on your [dashboard](https://app.launchdarkly.com) |
29 |
| - |
30 |
| -2. In your application code, use the feature's key to check whether the flag is on for each user: |
31 |
| - |
32 |
| - $user = new LaunchDarkly\LDUser("user@test.com"); |
33 |
| - if ($client->variation("your.flag.key", $user)) { |
34 |
| - # application code to show the feature |
35 |
| - } else { |
36 |
| - # the code to run if the feature is off |
37 |
| - } |
38 |
| - |
39 |
| -Fetching flags |
40 |
| --------------- |
41 |
| - |
42 |
| -There are two distinct methods of integrating LaunchDarkly in a PHP environment. |
43 |
| - |
44 |
| -* [Guzzle Cache Middleware](https://github.com/Kevinrob/guzzle-cache-middleware) to request and cache HTTP responses in an in-memory array (default) |
45 |
| -* [ld-relay](https://github.com/launchdarkly/ld-relay) to retrieve and store flags in Redis (recommended) |
46 |
| - |
47 |
| -We strongly recommend using the ld-relay. Per-flag caching (Guzzle method) is only intended for low-throughput environments. |
48 |
| - |
49 |
| -Using Guzzle |
50 |
| -============ |
51 |
| - |
52 |
| -Require Guzzle as a dependency: |
53 |
| - |
54 |
| - php composer.phar require "guzzlehttp/guzzle:6.2.1" |
55 |
| - php composer.phar require "kevinrob/guzzle-cache-middleware:1.4.1" |
56 |
| - |
57 |
| -It will then be used as the default way of fetching flags. |
58 |
| - |
59 |
| -With Guzzle, you could persist your cache somewhere other than the default in-memory store, like Memcached or Redis. You could then specify your cache when initializing the client with the [cache option](https://github.com/launchdarkly/php-client/blob/master/src/LaunchDarkly/LDClient.php#L44). |
60 |
| - |
61 |
| - $client = new LaunchDarkly\LDClient("YOUR_SDK_KEY", array("cache" => $cacheStorage)); |
62 |
| - |
63 |
| - |
64 |
| -Using LD-Relay |
65 |
| -============== |
66 |
| - |
67 |
| -The LaunchDarkly Relay Proxy ([ld-relay](https://github.com/launchdarkly/ld-relay)) consumes the LaunchDarkly streaming API and can update a database cache operating in your production environment. The ld-relay offers many benefits such as performance and feature flag consistency. With PHP applications, we strongly recommend setting up ld-relay with a database store. The database can be Redis, Consul, or DynamoDB. (For more about using LaunchDarkly with databases, see the [SDK reference guide](https://docs.launchdarkly.com/v2.0/docs/using-a-persistent-feature-store).) |
68 |
| - |
69 |
| -1. Set up ld-relay in [daemon-mode](https://github.com/launchdarkly/ld-relay#redis-storage-and-daemon-mode) with Redis |
70 |
| - |
71 |
| -2. Add the necessary dependency for the chosen database. |
72 |
| - |
73 |
| - For Redis: |
74 |
| - |
75 |
| - php composer.phar require "predis/predis:1.0.*" |
76 |
| - |
77 |
| - For Consul: |
78 |
| - |
79 |
| - php composer.phar require "sensiolabs/consul-php-sdk:2.*" |
80 |
| - |
81 |
| - For DynamoDB: |
82 |
| - |
83 |
| - php composer.phar require "aws/aws-sdk-php:3.*" |
84 |
| - |
85 |
| -3. Create the LDClient with the appropriate parameters for the chosen database. These examples show all of the available options. |
86 |
| - |
87 |
| - For Redis: |
88 |
| - |
89 |
| - $client = new LaunchDarkly\LDClient("your_sdk_key", [ |
90 |
| - 'feature_requester' => LaunchDarkly\Integrations\Redis::featureRequester(), |
91 |
| - 'redis_host' => 'your.redis.host', // defaults to "localhost" if not specified |
92 |
| - 'redis_port' => 6379, // defaults to 6379 if not specified |
93 |
| - 'redis_timeout' => 5, // connection timeout in seconds; defaults to 5 |
94 |
| - 'redis_prefix' => 'env1' // corresponds to the prefix setting in ld-relay |
95 |
| - 'predis_client' => $myClient // use this if you have already configured a Predis client instance |
96 |
| - ]); |
97 |
| - |
98 |
| - For Consul: |
99 |
| - |
100 |
| - $client = new LaunchDarkly\LDClient("your_sdk_key", [ |
101 |
| - 'feature_requester' => LaunchDarkly\Integrations\Consul::featureRequester(), |
102 |
| - 'consul_uri' => 'http://localhost:8500', // this is the default |
103 |
| - 'consul_prefix' => 'env1', // corresponds to the prefix setting in ld-relay |
104 |
| - 'consul_options' => array(), // you may pass any options supported by the Guzzle client |
105 |
| - 'apc_expiration' => 30 // expiration time for local caching, if you have apcu installed |
106 |
| - ]); |
107 |
| - |
108 |
| - For DynamoDB: |
109 |
| - |
110 |
| - $client = new LaunchDarkly\LDClient("your_sdk_key", [ |
111 |
| - 'feature_requester' => LaunchDarkly\Integrations\DynamoDb::featureRequester(), |
112 |
| - 'dynamodb_table' => 'your.table.name', // required |
113 |
| - 'dynamodb_prefix' => 'env1', // corresponds to the prefix setting in ld-relay |
114 |
| - 'dynamodb_options' => array(), // you may pass any options supported by the AWS SDK |
115 |
| - 'apc_expiration' => 30 // expiration time for local caching, if you have apcu installed |
116 |
| - ]); |
117 |
| - |
118 |
| -4. If you are using DynamoDB, you must create your table manually. It must have a partition key called "namespace", and a sort key called "key" (both strings). Note that by default the AWS SDK will attempt to get your AWS credentials and region from environment variables and/or local configuration files, but you may also specify them in `dynamodb_options`. |
119 |
| - |
120 |
| -5. If ld-relay is configured for [event forwarding](https://github.com/launchdarkly/ld-relay#event-forwarding), you can configure the LDClient to publish events to ld-relay instead of directly to `events.launchdarkly.com`. Using the `Guzzle` implementation of event publishing with ld-relay event forwarding can be an efficient alternative to the default `curl`-based event publishing. |
121 |
| - |
122 |
| - To forward events, add the following configuration properties to the configuration shown above: |
123 |
| - |
124 |
| - 'event_publisher' => LaunchDarkly\Integrations\Guzzle::eventPublisher(), |
125 |
| - 'events_uri' => 'http://your-ldrelay-host:8030' |
126 |
| - |
127 |
| -Using flag data from a file |
128 |
| ---------------------------- |
129 |
| - |
130 |
| -For testing purposes, the SDK can be made to read feature flag state from a file or files instead of connecting to LaunchDarkly. See [`LaunchDarkly\Integrations\Files`](https://github.com/launchdarkly/php-client/blob/master/src/LaunchDarkly/Integrations/Files.php) and ["Reading flags from a file"](https://docs.launchdarkly.com/docs/reading-flags-from-a-file). |
| 21 | +Check out our [documentation](http://docs.launchdarkly.com) for in-depth instructions on configuring and using LaunchDarkly. You can also head straight to the [complete reference guide for this SDK](http://docs.launchdarkly.com/docs/php-sdk-reference). |
131 | 22 |
|
132 |
| -Testing |
133 |
| -------- |
| 23 | +## Testing |
134 | 24 |
|
135 | 25 | We run integration tests for all our SDKs using a centralized test harness. This approach gives us the ability to test for consistency across SDKs, as well as test networking behavior in a long-running application. These tests cover each method in the SDK, and verify that event sending, flag evaluation, stream reconnection, and other aspects of the SDK all behave correctly.
|
136 | 26 |
|
137 |
| -Learn more |
138 |
| ------------ |
139 |
| - |
140 |
| -Check out our [documentation](http://docs.launchdarkly.com) for in-depth instructions on configuring and using LaunchDarkly. You can also head straight to the [complete reference guide for this SDK](http://docs.launchdarkly.com/docs/php-sdk-reference). |
141 |
| - |
142 |
| -Contributing |
143 |
| ------------- |
| 27 | +## Contributing |
144 | 28 |
|
145 |
| -We encourage pull-requests and other contributions from the community. We've also published an [SDK contributor's guide](http://docs.launchdarkly.com/docs/sdk-contributors-guide) that provides a detailed explanation of how our SDKs work. |
| 29 | +We encourage pull requests and other contributions from the community. Check out our [contributing guidelines](CONTRIBUTING.md) for instructions on how to contribute to this SDK. |
146 | 30 |
|
147 |
| -About LaunchDarkly |
148 |
| ------------------- |
| 31 | +## About LaunchDarkly |
149 | 32 |
|
150 | 33 | * LaunchDarkly is a continuous delivery platform that provides feature flags as a service and allows developers to iterate quickly and safely. We allow you to easily flag your features and manage them from the LaunchDarkly dashboard. With LaunchDarkly, you can:
|
151 | 34 | * Roll out a new feature to a subset of your users (like a group of users who opt-in to a beta tester group), gathering feedback and bug reports from real-world use cases.
|
|
0 commit comments