Skip to content

feat: add --memory-limit option for child processes#1

Open
Kalipso0505 wants to merge 1 commit intofeat/symfony-8-compatibilityfrom
feat/memory-limit-option
Open

feat: add --memory-limit option for child processes#1
Kalipso0505 wants to merge 1 commit intofeat/symfony-8-compatibilityfrom
feat/memory-limit-option

Conversation

@Kalipso0505
Copy link
Owner

@Kalipso0505 Kalipso0505 commented Mar 14, 2026

Problem

Tools like PHPStan can crash with PHP memory limit: 128M when invoked through phpcstd, because the child processes inherit the default memory_limit from php.ini. Users currently have no way to control the memory limit without modifying PHP configuration globally.

Solution

Adds a -m / --memory-limit CLI option that gets passed to all PHP-based child processes via php -d memory_limit=<value>.

phpcstd --memory-limit=-1      # unlimited memory for child processes
phpcstd --memory-limit=512M    # 512M limit
phpcstd                         # system default (unchanged behavior)

Implementation

  • New Cli::PARAMETER_MEMORY_LIMIT constant and CLI option in RunCommand
  • Value stored in Context::$memoryLimit, passed to tools via Tool::setContext()
  • Tool::execute() prepends php -d memory_limit=<value> to the command when set
  • New abstract method Tool::supportsMemoryLimit() forces every subclass to explicitly declare support
  • Non-PHP binaries like composer return false to skip the wrapping

Changes

File Change
Cli.php New PARAMETER_MEMORY_LIMIT constant
Context.php New $memoryLimit property
RunCommand.php Register CLI option, pass context to tools
Tool.php setContext(), memory-limit logic in execute(), abstract supportsMemoryLimit()
ComposerNormalize.php supportsMemoryLimit() returns false
All other tools (9) supportsMemoryLimit() returns true

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant