Skip to content
Closed
Changes from all commits
Commits
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
20 changes: 13 additions & 7 deletions src/LaunchDarkly/LDClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,19 @@ public function __construct(string $sdkKey, array $options = [])
{
$apcuLoaded = extension_loaded('apcu');

if ($apcuLoaded && \apcu_enabled()) {
$options['instance_id'] = \apcu_entry('ld::instanceid', function ($key) {
$uuid = Uuid::uuid4()->toString();
return $uuid;
});
} elseif (php_sapi_name() === 'cli') {
$options['instance_id'] = Uuid::uuid4()->toString();
if (!isset($options['instance_id'])) {
// Every client instance must send an `X-LaunchDarkly-Instance-Id` header; the
// apcu case shares a per-process id, any other process (CLI and
// long-running SAPIs, including PHP's built-in web server cli-server)
// mints a fresh UUID per client.
if ($apcuLoaded && \apcu_enabled()) {
$options['instance_id'] = \apcu_entry('ld::instanceid', function ($key) {
$uuid = Uuid::uuid4()->toString();
return $uuid;
});
} else {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change will explode the cardinality of that data, which has effects on relay behavior around usage metrics and o11y.

$options['instance_id'] = Uuid::uuid4()->toString();
}
}

$this->_sdkKey = $sdkKey;
Expand Down
Loading