Skip to content
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions .changeset/old-onions-attend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"posthog-php": patch
---

Move const inside class to prevent memory leaks in worker mode
5 changes: 2 additions & 3 deletions lib/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@
use PostHog\Consumer\Socket;
use Symfony\Component\Clock\Clock;

const SIZE_LIMIT = 50_000;

/**
* PostHog PHP SDK client for event capture, user identification, feature flags, and error tracking.
*/
class Client implements FeatureFlagEvaluationsHost
{
private const SIZE_LIMIT = 50_000;
private const CONSUMERS = [
"socket" => Socket::class,
"file" => File::class,
Expand Down Expand Up @@ -167,7 +166,7 @@ public function __construct(
$this->groupTypeMapping = [];
$this->cohorts = [];
$this->featureFlagsByKey = [];
$this->distinctIdsFeatureFlagsReported = new SizeLimitedHash(SIZE_LIMIT);
$this->distinctIdsFeatureFlagsReported = new SizeLimitedHash(self::SIZE_LIMIT);
$this->flagsEtag = null;

if ($this->enabled) {
Expand Down
6 changes: 3 additions & 3 deletions lib/FeatureFlag.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

use Symfony\Component\Clock\Clock;

const LONG_SCALE = 0xfffffffffffffff;

/**
* Local feature flag matching helpers.
*
* @internal
*/
class FeatureFlag
{
private const LONG_SCALE = 0xfffffffffffffff;

/**
* Match a single property filter against provided property values.
*
Expand Down Expand Up @@ -585,7 +585,7 @@ private static function hash($key, $distinctId, $salt = "")
$hashKey = sprintf("%s.%s%s", $key, $distinctId, $salt);
$hashVal = base_convert(substr(sha1($hashKey), 0, 15), 16, 10);

return $hashVal / LONG_SCALE;
return $hashVal / self::LONG_SCALE;
}

private static function getMatchingVariant($flag, $distinctId)
Expand Down
Loading