From f72a5fe203528591ec219e7ed9c9ab0593f79777 Mon Sep 17 00:00:00 2001 From: zip-fa Date: Wed, 12 Feb 2025 15:23:02 +0200 Subject: [PATCH 1/2] fix: move const inside class to prevent memory leaks in worker mode --- lib/Client.php | 5 ++--- lib/FeatureFlag.php | 6 +++--- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/Client.php b/lib/Client.php index ff3f082..cfd4bbc 100644 --- a/lib/Client.php +++ b/lib/Client.php @@ -9,13 +9,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, @@ -157,7 +156,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; ExceptionCapture::configure($this, $options['error_tracking'] ?? []); 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) From 9ccb6ae5c7b9a2083ef5e26f978518e954197beb Mon Sep 17 00:00:00 2001 From: zip-fa Date: Sat, 30 May 2026 12:49:37 +0300 Subject: [PATCH 2/2] chore: add changeset --- .changeset/old-onions-attend.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/old-onions-attend.md 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