megalinter
megalinter copied to clipboard
Disable PHP Memory Limit in Docker container
The default memory limit of 128M
is not enough to lint larger projects.
Since this is a development tool (running on trusted input, or in isolated environments) and not a production server its safe to disable this limit.
Fixes:
PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate xxxxx bytes)
Proposed Changes:
- Disable PHP memory limit
Current Workaround:
Apply the changes by extending the Docker image with an new Dockerfile.
FROM megalinter/megalinter:latest
RUN echo 'memory_limit = -1' > /etc/php7/conf.d/02_memlimit.ini \
&& echo 'memory_limit = -1' > /etc/php8/conf.d/02_memlimit.ini
What PHP linter run you in trouble (PHP built-in or PHPLint ?)
I'm :-1: to apply unlimited memory usage by default. I suggest this alternative if you've a BIG file that consume more than 128Mo
Put into your source code a my-php.ini
file with at least such contents
memory_limit = ${PHP_MEMORY_LIMIT}
And if you want to pass a memory limit (like 256M
) or want unlimited (-1
), depending of your linter, put in you .mega-linter.yml
config file
PHP_BUILTIN_ARGUMENTS: "-c /tmp/lint/my-php.ini"
PHPLinter is not yet ready to accept PHP external config file -c
(see https://github.com/overtrue/phplint/blob/8.1/src/Linter.php#L157-L167)
And to set your PHP_MEMORY_LIMIT
env var, call MegaLinter with -e PHP_MEMORY_LIMIT=256M
or -e PHP_MEMORY_LIMIT=-1
syntax
https://www.php.net/manual/en/configuration.file.php#example-27
About PHPLint missing feature, I've just opened a report at https://github.com/overtrue/phplint/issues/137
FYI: PHPLint has been released with new versions :
@stackcoder If you want to contribute, please share your source code and the linter that raised your memory error (contextual data was not identified in your primary request)
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.
If you think this pull request should stay open, please remove the O: stale 🤖
label or comment on the pull request.
@llaville Sorry, I can't share the source code. Unfortunately it happened when analyzing proprietary code.
Why should a PHP linter have a memory limit, and an another one not? Just because PHP was build to serve webpages is not a valid argument here. Also I expect when system stability is required while running megalinter the way to go is limiting the container or virtual machine, not the application which is possibly processing untrusted data.