diff --git a/.changeset/old-onions-attend.md b/.changeset/old-onions-attend.md new file mode 100644 index 0000000..9763399 --- /dev/null +++ b/.changeset/old-onions-attend.md @@ -0,0 +1,5 @@ +--- +"posthog-php": patch +--- + +Move const inside class to prevent memory leaks in worker mode diff --git a/lib/Client.php b/lib/Client.php index 90b5d35..cbb5691 100644 --- a/lib/Client.php +++ b/lib/Client.php @@ -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, @@ -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) { diff --git a/lib/FeatureFlag.php b/lib/FeatureFlag.php index dc2c2ab..3c1f77a 100644 --- a/lib/FeatureFlag.php +++ b/lib/FeatureFlag.php @@ -4,8 +4,6 @@ use Symfony\Component\Clock\Clock; -const LONG_SCALE = 0xfffffffffffffff; - /** * Local feature flag matching helpers. * @@ -13,6 +11,8 @@ */ class FeatureFlag { + private const LONG_SCALE = 0xfffffffffffffff; + /** * Match a single property filter against provided property values. * @@ -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)