Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: allow specifying memory limit #3947

Merged
merged 1 commit into from
Aug 6, 2020

Conversation

mr-feek
Copy link
Contributor

@mr-feek mr-feek commented Aug 5, 2020

should close #3945

$memoryLimit = $options['memory-limit'];

if (!is_scalar($memoryLimit)) {
throw new ConfigException('Invalid memory limit specified.');
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this case is even possible -- however without the scalar check, psalm complained about the following:

ERROR: PossiblyInvalidCast - src/psalm.php:202:38 - list<mixed> cannot be cast to string (see https://psalm.dev/190)
    ini_set('memory_limit', (string) $memoryLimit);

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getopt() will return a list if you specify the option multiple times.
E.g psalm --memory-limit=1 --memory-limit=2 will result in

array(1) {
  'memory-limit' =>
  array(2) {
    [0] =>
    string(1) "1"
    [1] =>
    string(1) "2"
  }
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

today I learned!

@muglug muglug merged commit ec7876b into vimeo:master Aug 6, 2020
@muglug
Copy link
Collaborator

muglug commented Aug 6, 2020

Thanks!

@mshamaseen
Copy link

@muglug how to use this? I tried --memory-limit=1024M , --memory-limit=1024 but both of them failed.

@AndrolGenhald
Copy link
Collaborator

@mshamaseen It appears that it must be specified in bytes (--memory-limit=1073741824).

@orklah
Copy link
Collaborator

orklah commented Jul 1, 2022

ini_set format should be accepted, a string is a valid scalar. So '1024M' should work.

Most probably you have a ini_set('memory_limit') in your own code that gets executed by your autoloader. Could you check if it could be the case? Try with --debug-by-line to try to see where Psalm crash

@mshamaseen
Copy link

mshamaseen commented Jul 5, 2022

@orklah @AndrolGenhald it does not work, it says:

vendor/bin/psalm --memory-limit=1073741824 ${CHANGED_FILES}

Target PHP version: 8.1 (inferred from composer.json) Scanning files... PHP Fatal error: Allowed memory size of 1073741824 bytes exhausted (tried to allocate 491520 bytes) in /**/vendor/barryvdh/laravel-ide-helper/resources/views/helper.php on line 34 PHP Fatal error: Allowed memory size of 1073741824 bytes exhausted (tried to allocate 65536 bytes) in /**/vendor/nunomaduro/collision/src/Highlighter.php on line 235

@AndrolGenhald
Copy link
Collaborator

... --memory-limit=1073741824 ... Allowed memory size of 1073741824 bytes exhausted

Looks fine to me, have you tried a higher limit?

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.

Memory limit flag?
6 participants