Skip to content

Commit 384a406

Browse files
committed
Add documentation for GuzzleEventPublisher and CurlEventPublisher
1 parent ae90fe1 commit 384a406

File tree

5 files changed

+49
-9
lines changed

5 files changed

+49
-9
lines changed

README.md

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,23 +58,40 @@ Require Guzzle as a dependency:
5858

5959
It will then be used as the default way of fetching flags.
6060

61-
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#L42).
61+
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).
6262

6363
$client = new LaunchDarkly\LDClient("YOUR_SDK_KEY", array("cache" => $cacheStorage));
6464

6565

6666
Using LD-Relay
6767
==============
6868

69-
* Setup [ld-relay](https://github.com/launchdarkly/ld-relay) in [daemon-mode](https://github.com/launchdarkly/ld-relay#redis-storage-and-daemon-mode) with Redis
69+
The LaunchDarkly Relay Proxy ([ld-relay](https://github.com/launchdarkly/ld-relay)) consumes the LaunchDarkly streaming API and can update
70+
a Redis 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 Redis store.
7071

71-
* Require Predis as a dependency:
72+
1. Set up ld-relay in [daemon-mode](https://github.com/launchdarkly/ld-relay#redis-storage-and-daemon-mode) with Redis
7273

73-
php composer.phar require "predis/predis:1.0.*"
74+
2. Require Predis as a dependency:
7475

75-
* Create the LDClient with the Redis feature requester as an option:
76+
php composer.phar require "predis/predis:1.0.*"
7677

77-
$client = new LaunchDarkly\LDClient("your_sdk_key", ['feature_requester_class' => 'LaunchDarkly\LDDFeatureRequester', 'redis_host' => 'your.redis.host', 'redis_port' => 6379]);
78+
3. Create the LDClient with the Redis feature requester as an option:
79+
80+
$client = new LaunchDarkly\LDClient("your_sdk_key", [
81+
'feature_requester_class' => 'LaunchDarkly\LDDFeatureRequester',
82+
'redis_host' => 'your.redis.host',
83+
'redis_port' => 6379
84+
]);
85+
86+
4. 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 `GuzzleEventPublisher` with ld-relay event forwarding can be an efficient alternative to the default `curl`-based event publishing.
87+
88+
$client = new LaunchDarkly\LDClient("your_sdk_key", [
89+
'event_publisher_class' => 'LaunchDarkly\GuzzleEventPublisher',
90+
'events_uri' => 'http://your-ldrelay-host:8030',
91+
'feature_requester_class' => 'LaunchDarkly\LDDFeatureRequester',
92+
'redis_host' => 'your.redis.host',
93+
'redis_port' => 6379
94+
]);
7895

7996
Testing
8097
-------

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"zendframework/zend-serializer": "^2.7"
2828
},
2929
"suggest": {
30-
"guzzlehttp/guzzle": "(^6.2.1) Required when using RelayEventPublisher or the default FeatureRequester",
30+
"guzzlehttp/guzzle": "(^6.2.1) Required when using GuzzleEventPublisher or the default FeatureRequester",
3131
"kevinrob/guzzle-cache-middleware": "(^1.4.1) Recommended for performance when using the default FeatureRequester",
3232
"predis/predis": "(^1.0) Required when using LDDFeatureRequester"
3333
},

src/LaunchDarkly/CurlEventPublisher.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
<?php
22
namespace LaunchDarkly;
33

4+
/**
5+
* Sends events to the LaunchDarkly service using the `curl` command line tool.
6+
* The `curl` requests are executed as background processes in order to
7+
* minimize overhead to the PHP request. This `EventPublisher` implementation
8+
* is the default for `LDClient`.
9+
*
10+
* `curl` must be installed in the environment's search path, or otherwise the
11+
* absolute path to the executable must be specified using the `'curl'` option
12+
* for `LDClient`.
13+
*/
414
class CurlEventPublisher implements EventPublisher
515
{
616
private $_sdkKey;

src/LaunchDarkly/EventPublisher.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
<?php
22
namespace LaunchDarkly;
33

4+
/**
5+
* Provides a transport mechanism for sending events to the LaunchDarkly service.
6+
*/
47
interface EventPublisher {
58
/**
69
* @param string $sdkKey The SDK key for your account

src/LaunchDarkly/RelayEventPublisher.php renamed to src/LaunchDarkly/GuzzleEventPublisher.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,17 @@
44
use GuzzleHttp\Client;
55
use Psr\Log\LoggerInterface;
66

7-
class RelayEventPublisher implements EventPublisher
7+
/**
8+
* Sends events to the LaunchDarkly service using the GuzzleHttp client.
9+
* This `EventPublisher` implement provides an in-process alternative to
10+
* the default `CurlEventPublisher` implementation which forks processes.
11+
*
12+
* Note that this implementation executes synchronously in the request
13+
* handler. In order to minimize request overhead, we recommend that you
14+
* set up `ld-relay` in your production environment and configure the
15+
* `events_uri` option for `LDClient` to publish to `ld-relay`.
16+
*/
17+
class GuzzleEventPublisher implements EventPublisher
818
{
919
/** @var string */
1020
private $_sdkKey;
@@ -45,7 +55,7 @@ public function publish($payload) {
4555

4656
return $response->getStatusCode() < 300;
4757
} catch (\Exception $e) {
48-
$this->_logger->warning("RelayEventPublisher::publish caught $e");
58+
$this->_logger->warning("GuzzleEventPublisher::publish caught $e");
4959
return false;
5060
}
5161
}

0 commit comments

Comments
 (0)