Problem/Motivation
The composer phpcs exceeds the php memory limit if it's 256MB or lower.
Steps to reproduce
Set memory limit to 256M and run composer phpcs:
The PHP_CodeSniffer "phpcs" command ran out of memory.
Either raise the "memory_limit" of PHP in the php.ini file or raise the memory limit at runtime
using `phpcs -d memory_limit=512M` (replace 512M with the desired memory limit).
Proposed resolution
Set memory limit to -1 (unlimited) for phpcs and phpcbf commands.
Remaining tasks
User interface changes
Introduced terminology
API changes
Data model changes
Release notes snippet
Issue fork drupal-3549208
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
- 3549208-set-memory-limit
changes, plain diff MR !13333
Comments
Comment #3
mstrelan commentedComment #4
cilefen commentedWhy not -1?
Comment #5
mstrelan commentedCurrently it passes with 384 MB so the current requirement is somewhere between 256 and 384. If we set it to -1 and the process starts requiring more than 512 MB (or possibly much more) then that's a good indicator we might have a problem. Maybe phpcs started scanning node_modules or vendor or something like that.
Comment #6
smustgrave commentedSeems straight forward and explanation makes sense
Comment #7
xjmSo we were taking the approach of allowing the memory limit to be bypassed when running the commit check script. I'm not sure about harcoding a specific memory limit like this. Can the developer still override it to something higher or lower?
I'm not sure scanning all of core is the default operation (I'm assuming the IS means it OOMs when scanning all of core).
Comment #8
mstrelan commentedI had never considered that you could pass additional arguments. The default is to scan all of core, but you can indeed pass a path to scan instead.
AFAIK the supported way to set the memory limit for this command is
COMPOSER_MEMORY_LIMIT=512M composer phpcs. I tested this on this branch with 16M and it OOM'd straight away, so I guess that's working.I also tried the inverse, by setting the memory limit in composer.json to 16M and 512M in the env var, but that also OOM'd.
TL;DR the developer can set it lower but not higher. So maybe -1 is the way to go? But in saying that, the command is not particularly useful for scanning anything other than core, since core has its own specific rules and path inclusions.
Comment #9
xjmOoh yeah, if we can't override it to be higher, I think that's not good. Thanks!
The commit check script fix has landed BTW, so committers will already be
-1ing up our machines by default when we commit stuff.Comment #11
mstrelan commentedRebased and updated to -1 instead of 512M
Comment #12
dcam commentedI'm not sure there's a lot to do for reviewing this one, but for what it's worth I did the following:
It looks good to me.
Comment #17
catchCommitted/pushed to main and cherry-picked back through to 11.4.x, thanks!