Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
d29f2d2
add segment matching logic & ability to get segments from LD
eli-darkly Feb 3, 2018
60dec53
misc fixes
eli-darkly Feb 3, 2018
252f270
misc fixes, tests
eli-darkly Feb 5, 2018
120c7e4
more tests
eli-darkly Feb 6, 2018
d6a9a2b
Merge pull request #17 from launchdarkly/eb/segments
eli-darkly Feb 6, 2018
d16d1b6
Merge branch 'segments'
eli-darkly Feb 21, 2018
d0c46bb
version 3.0.0
eli-darkly Feb 21, 2018
e26219b
migrate to CircleCI 2
eli-darkly Mar 30, 2018
a9e9647
typo
eli-darkly Mar 30, 2018
16dd1f5
sudo
eli-darkly Mar 30, 2018
7d09d53
misc fixes
eli-darkly Mar 30, 2018
917b4f1
fixing integration test
eli-darkly Mar 30, 2018
1e3160d
misc fixes
eli-darkly Mar 30, 2018
d9957d8
misc fixes
eli-darkly Mar 30, 2018
cddd7c0
don't need Apache
eli-darkly Mar 30, 2018
b822335
misc fixes
eli-darkly Mar 30, 2018
0c2b351
add a job to run PHP 5.5
eli-darkly Mar 30, 2018
e79714e
fix syntax
eli-darkly Mar 30, 2018
0df4152
typo
eli-darkly Mar 30, 2018
6b84020
misc fixes
eli-darkly Mar 30, 2018
99ff3dc
try to make 7.2 build work
eli-darkly Mar 30, 2018
52267f2
add JUnit output for integration tests
eli-darkly Mar 30, 2018
07b9b24
Merge pull request #18 from launchdarkly/eb/ch15552/circle2
eli-darkly Mar 30, 2018
847b0a7
remove CodeClimate from readme
eli-darkly Apr 16, 2018
3224f38
add variation index to feature request events
eli-darkly Apr 30, 2018
639a0e7
add more unit tests for flag evaluation
eli-darkly Apr 30, 2018
b94d8c4
Merge pull request #19 from launchdarkly/eb/ch16122/code-climate
eli-darkly Apr 30, 2018
9119093
Merge pull request #20 from launchdarkly/eb/ch16654/variation-index
eli-darkly Apr 30, 2018
92b988a
Merge pull request #21 from launchdarkly/eb/eval-tests
eli-darkly Apr 30, 2018
9b16b6a
get flag properties for event even if user is invalid
eli-darkly May 4, 2018
f87bbc1
typo
eli-darkly May 4, 2018
aed7759
fix Redix key for segment retrieval
eli-darkly May 4, 2018
6210902
Merge pull request #22 from launchdarkly/eb/fix-event-properties
eli-darkly May 4, 2018
a23be99
set event version even if evaluation falls through to default
eli-darkly May 4, 2018
e881e2d
Merge pull request #23 from launchdarkly/eb/event-version-with-default
eli-darkly May 4, 2018
83b0ee5
Merge branch 'master' of github.com:launchdarkly/php-client
eli-darkly May 25, 2018
8ecc0c5
Merge branch 'master' of github.com:launchdarkly/php-client
eli-darkly Jun 26, 2018
56b14b2
treat most 4xx errors as unrecoverable
eli-darkly Jun 26, 2018
7a0eaf3
formatting
eli-darkly Jun 26, 2018
fad3418
Merge pull request #24 from launchdarkly/eb/ch18901/4xx-errors
eli-darkly Jun 26, 2018
1ac40c9
treat 400 error as recoverable
eli-darkly Jun 27, 2018
0a566be
Merge pull request #25 from launchdarkly/eb/ch18901/400-error
eli-darkly Jun 27, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/LaunchDarkly/GuzzleEventPublisher.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,13 @@ public function publish($payload)
$this->_logger->warning("GuzzleEventPublisher::publish caught $e");
return false;
}
if ($response && ($response->getStatusCode() == 401)) {
throw new InvalidSDKKeyException();
if ($response && ($response->getStatusCode() >= 300)) {
$this->_logger->error(Util::httpErrorMessage($response->getStatusCode(), 'event posting', 'some events were dropped'));
if (!Util::isHttpErrorRecoverable($response->getStatusCode())) {
throw new UnrecoverableHTTPStatusException($response->getStatusCode());
}
return false;
}
return $response && ($response->getStatusCode() < 300);
return $response != null;
}
}
6 changes: 3 additions & 3 deletions src/LaunchDarkly/GuzzleFeatureRequester.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ public function getAllFeatures()

private function handleUnexpectedStatus($code, $method)
{
$this->_logger->error("$method received an unexpected HTTP status code $code");
if ($code == 401) {
throw new InvalidSDKKeyException();
$this->_logger->error(Util::httpErrorMessage($code, $method, 'default value was returned'));
if (!Util::isHttpErrorRecoverable($code)) {
throw new UnrecoverableHTTPStatusException($code);
}
}
}
9 changes: 0 additions & 9 deletions src/LaunchDarkly/InvalidSDKKeyException.php

This file was deleted.

16 changes: 8 additions & 8 deletions src/LaunchDarkly/LDClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ public function variation($key, $user, $default = false)
}
try {
$flag = $this->_featureRequester->getFeature($key);
} catch (InvalidSDKKeyException $e) {
$this->handleInvalidSDKKey();
} catch (UnrecoverableHTTPStatusException $e) {
$this->handleUnrecoverableError();
return $default;
}

Expand Down Expand Up @@ -275,8 +275,8 @@ public function allFlags($user)
}
try {
$flags = $this->_featureRequester->getAllFeatures();
} catch (InvalidSDKKeyException $e) {
$this->handleInvalidSDKKey();
} catch (UnrecoverableHTTPStatusException $e) {
$this->handleUnrecoverableError();
return null;
}
if ($flags === null) {
Expand Down Expand Up @@ -314,8 +314,8 @@ public function flush()
{
try {
return $this->_eventProcessor->flush();
} catch (InvalidSDKKeyException $e) {
$this->handleInvalidSDKKey();
} catch (UnrecoverableHTTPStatusException $e) {
$this->handleUnrecoverableError();
}
}

Expand Down Expand Up @@ -345,9 +345,9 @@ protected function _get_default($key, $default)
}
}

protected function handleInvalidSDKKey()
protected function handleUnrecoverableError()
{
$this->_logger->error("Received 401 error, no further HTTP requests will be made during lifetime of LDClient since SDK key is invalid");
$this->_logger->error("Due to an unrecoverable HTTP error, no further HTTP requests will be made during lifetime of LDClient");
$this->_offline = true;
}
}
15 changes: 15 additions & 0 deletions src/LaunchDarkly/UnrecoverableHTTPStatusException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
namespace LaunchDarkly;

/**
* Used internally.
*/
class UnrecoverableHTTPStatusException extends \Exception
{
public $status;

public function __construct($status)
{
$this->status = $status;
}
}
26 changes: 26 additions & 0 deletions src/LaunchDarkly/Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,30 @@ public static function newFeatureRequestEvent($key, $user, $variation, $value, $
$event['prereqOf'] = $prereqOf;
return $event;
}

/**
* @param $status int
* @return boolean
*/
public static function isHttpErrorRecoverable($status)
{
if ($status >= 400 && $status < 500) {
return ($status == 400) || ($status == 408) || ($status == 429);
}
return true;
}

/**
* @param $status int
* @param $context string
* @param $retryMessage string
* @return string
*/
public static function httpErrorMessage($status, $context, $retryMessage)
{
return 'Received error ' . $status
. (($status == 401) ? ' (invalid SDK key)' : '')
. ' for ' . $context . ' - '
. (Util::isHttpErrorRecoverable($status) ? $retryMessage : 'giving up permanently');
}
}