fix: move const inside class to prevent memory leaks in worker mode#152
Merged
Conversation
|
Reviews (1): Last reviewed commit: "fix: move const inside class to prevent ..." | Re-trigger Greptile |
Member
|
@zip-fa can you add a changeset pls? https://github.com/PostHog/posthog-php/blob/main/RELEASING.md |
Contributor
Author
|
@marandaneto done |
marandaneto
approved these changes
May 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
💡 Motivation and Context
PHP applications running in long-lived worker modes (FrankenPHP, Swoole, RoadRunner, Laravel Octane) suffer from memory leaks caused by namespace-level constants in
lib/Client.phpandlib/FeatureFlag.php.When
SIZE_LIMITandLONG_SCALEare declared at the namespace level withconst, PHP re-evaluates and allocates them on every request in persistent worker processes, since namespace constants are not garbage-collected between requests in these runtimes. Moving them toprivate conston their respective classes ties their lifecycle to the class autoloader cache, which is loaded once and reused — eliminating the leak.💚 How did you test it?
memory_get_usage()over 10,000+ requests — memory remained stable after the fix, whereas it grew linearly before.composer test).self::SIZE_LIMITandself::LONG_SCALEresolve to the same values as the original namespace constants.📝 Checklist
If releasing new changes
pnpm changesetto generate a changeset fileFixes #153