feat: add --memory-limit option for child processes#1
Open
Kalipso0505 wants to merge 1 commit intofeat/symfony-8-compatibilityfrom
Open
feat: add --memory-limit option for child processes#1Kalipso0505 wants to merge 1 commit intofeat/symfony-8-compatibilityfrom
Kalipso0505 wants to merge 1 commit intofeat/symfony-8-compatibilityfrom
Conversation
Adds a -m/--memory-limit CLI parameter that sets the PHP memory limit for all child processes (phpstan, ecs, etc.). When set, the tool binary is invoked via `php -d memory_limit=X <binary>` instead of directly. Non-PHP binaries (e.g. composer) opt out via supportsMemoryLimit(), which is abstract to enforce explicit implementation in every Tool subclass. Usage: phpcstd --memory-limit=-1 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.
Problem
Tools like PHPStan can crash with
PHP memory limit: 128Mwhen invoked through phpcstd, because the child processes inherit the defaultmemory_limitfromphp.ini. Users currently have no way to control the memory limit without modifying PHP configuration globally.Solution
Adds a
-m/--memory-limitCLI option that gets passed to all PHP-based child processes viaphp -d memory_limit=<value>.Implementation
Cli::PARAMETER_MEMORY_LIMITconstant and CLI option inRunCommandContext::$memoryLimit, passed to tools viaTool::setContext()Tool::execute()prependsphp -d memory_limit=<value>to the command when setTool::supportsMemoryLimit()forces every subclass to explicitly declare supportcomposerreturnfalseto skip the wrappingChanges
Cli.phpPARAMETER_MEMORY_LIMITconstantContext.php$memoryLimitpropertyRunCommand.phpTool.phpsetContext(), memory-limit logic inexecute(), abstractsupportsMemoryLimit()ComposerNormalize.phpsupportsMemoryLimit()returnsfalsesupportsMemoryLimit()returnstrue