api-platform raise memory limit on php docker image - php

following the tutorial using docker for setting up api-platform all worked well so far. Now I'm trying to install doctrine migrations using:
docker-compose exec php composer require doctrine/doctrine-migrations-bundle "dev-master"
But I'm getting:
Fatal error: Allowed memory size of 1610612736 bytes exhausted (tried to allocate 4096 bytes) in phar:///usr/bin/composer/src/Composer/DependencyResolver/RuleWatchGraph.php on line 52
How would I raise the allow memory in that php docker container? Should I add this to api/docker/php/php.ini? I tried and did another docker-compose up but nothing changes.
Thanks!
Kim

1610612736 Bytes are approximately 1.6 GB
It's pretty uncommon that a composer invocation requires so much memory.
I guess, the real cause is not the memory limit, but if you want to increaese it anyway you should probably try this:
docker-compose exec php \
php -d memory_limit=2G \
/usr/bin/composer require doctrine/doctrine-migrations-bundle
P.S.
doctrine/doctrine-migrations-bundle:dev-master could not be resolved in my installaton, so I simply omitted it

Related

composer still exhausted even allocated with bigger memory

Already updated the memory_limit on php.ini by about 1G and doing also php -d memory_limit=1G composer.phar update and I can see the allowed memory is bigger than the displayed memory attempt 1610612736 where composer says tried to allocate 4096 bytes any help, ideas?
Try using composer diagnose.
The diagnose command performs automated checks for many common problems. This can help you spot find potential bottlenecks/bugs if there are any.
https://getcomposer.org/doc/03-cli.md#diagnose
From Composer documentation:
Note: Composer internally increases the memory_limit to 1.5G.
https://getcomposer.org/doc/articles/troubleshooting.md#memory-limit-errors
Have this a go:
php -d memory_limit=-1 composer.phar update
If this does not work there are more solutions here:
Composer Update failed -- out of memory

Composer: Allowed memory size error when installing package

When I run composer require yab/laravel-scout-mysql-driver this is the output that I get:
Using version ^2.40 for yab/laravel-scout-mysql-driver
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
PHP Fatal error: Allowed memory size of 1610612736 bytes exhausted (tried to allocate 4096 bytes) in phar:///usr/local/Cellar/composer/1.3.2/libexec/composer.phar/src/Composer/DependencyResolver/RuleWatchGraph.php on line 52
Fatal error: Allowed memory size of 1610612736 bytes exhausted (tried to allocate 4096 bytes) in phar:///usr/local/Cellar/composer/1.3.2/libexec/composer.phar/src/Composer/DependencyResolver/RuleWatchGraph.php on line 52
Check https://getcomposer.org/doc/articles/troubleshooting.md#memory-limit-errors for more info on how to handle out of memory errors.
I'm running Composer 1.9.2.
Here are the last few lines of the output when I use -vvv:
Reading /Users/redacted/.composer/cache/repo/https---repo.packagist.org/provider-ircmaxell$password-compat.json from cache
Reading /Users/redacted/.composer/cache/repo/https---repo.packagist.org/provider-paragonie$constant-time-encoding.json from cache
Reading /Users/redacted/.composer/cache/repo/https---repo.packagist.org/provider-yab$laravel-scout-mysql-driver.json from cache
Reading /Users/redacted/.composer/cache/repo/https---repo.packagist.org/provider-symfony$class-loader.json from cache
Reading /Users/redacted/.composer/cache/repo/https---repo.packagist.org/provider-symfony$polyfill-apcu.json from cache
Reading /Users/redacted/.composer/cache/repo/https---repo.packagist.org/provider-symfony$polyfill-xml.json from cache
Reading /Users/redacted/.composer/cache/repo/https---repo.packagist.org/provider-gecko-packages$gecko-php-unit.json from cache
PHP Fatal error: Allowed memory size of 1610612736 bytes exhausted (tried to allocate 4096 bytes) in phar:///usr/local/Cellar/composer/1.3.2/libexec/composer.phar/src/Composer/DependencyResolver/RuleWatchGraph.php on line 52
Fatal error: Allowed memory size of 1610612736 bytes exhausted (tried to allocate 4096 bytes) in phar:///usr/local/Cellar/composer/1.3.2/libexec/composer.phar/src/Composer/DependencyResolver/RuleWatchGraph.php on line 52
Check https://getcomposer.org/doc/articles/troubleshooting.md#memory-limit-errors for more info on how to handle out of memory errors.
My memory limit is 128M. https://getcomposer.org/doc/articles/troubleshooting.md#memory-limit-errors doesn't seem to provide lot of insight other than to increase my memory limit but it seems like 128M should be sufficient?
php -d memory_limit=-1 /usr/local/bin/composer require yab/laravel-scout-mysql-driver did not help - I got "Allowed memory size of 1610612736 bytes exhausted" errors. Same thing with memory_limit=1024M.
I did php --ini and from that got /usr/local/etc/php/7.1/php.ini, which I edited to change the memory limit 1024MB and am getting the same thing: "Allowed memory size of 1610612736 bytes exhausted".
It's weird that the "allowed memory size" is the exact same in every instance. It's like nothing I'm doing is actually changing the memory size.
Any ideas?
(may be a) DUPLICATE of Composer Update failed -- out of memory
I had the same issue with the same versions (PHP 7.1, Composer 1.9.x) and exactly same memory limit (which after investigation is coded inside/defined in composer).
The first thing to do when you encounter this kind of error is to tell composer to not limit the memory with a variable, like this:
COMPOSER_MEMORY_LIMIT=-1 composer require "xxx/yyy"
This is the recommended way but sometime it just doesn't work.
In my project, it seems that the composer.lock get corrupted every time I do a composer require xxx.
To "fix" it, I do this:
remove your vendor folder (rm -fr vendor)
remove composer.lock (rm composer.lock)
make sure that your composer.json contains your new requirement (it should be there because of the previous composer require), if not, add it
do a fresh composer install
At this point, either you will clearly see a dependency issue, or everything will be installed.
Do not delete composer.lock as was recommended in previous answer for projects, which are dunning on the production. Moreover, ensure that it does exist, it helps both to save lots of resources and time on avoid recalculation of dependencies by composer + locking of libraries versions make project behavior more predictable.
"composer.lock" is a must have for any project and it's removal kinda similar to composer update for all. You might get in trouble because of the unlocking and, as a result, fetching newer versions of the libraries into the project and get breaking changes. In most cases in composer.json, libraries versions are not too strict (people usually put there major version, in best case minor version, and almost never version of the patch) so that removal of the composer.lock for a big project might lead to the huge issues and it will not really help, because composer will have to fetch all possible branches and version of all required libraries, which were defined in composer.json just to generate a composer.lock .
your solution with php -d memory_limit=-1 /usr/local/bin/composer require yab/laravel-scout-mysql-driver was a correct and in most cases it works. Thing is that seems to me that you have limited amount of available memory. In this case you can try to do one from the next things:
in case if you are inside the docker container in OSX env, reconfigure your VM there (check Preferences of the docker and you can increase amount of memory and CPU, which can be allocated by docker - this is a very popular issue: people forget that in OSX there is a VM running to serve docker, so that they have by default limitations in CPU/MEM/disk allocation)
in case if docker on the OSX is not the case and host has a real limitation with available memory, then ideally to use dev environment, which is has either more memory or add a swap for this purposes.
From my observations, usually composer requires MOST of the memory exactly to recalculate all the dependencies, find out matching versions for the platform and take a hash from the remote repository and put all this info into the composer.lock. After composer.lock is generated, it does not need too much memory, so that install works perfectly with very limited amount of memory. So sometimes I used a workaround, like (which is quite terrible, and depends on luck, but sometimes worked):
a. run composer require and wait until a new record appears in the composer.lock and then kill the process (to avoid revert of record in composer.lock, which is happens automatically on install failure). If you are lucky you will get it updated before memory limit is reached.
b. then just run composer install and get finally library installed.
If none of the approaches worked, you can try to add manually record in the composer.lock, with proper hash. In this case you can avoid recalculation of all dependencies and intermediately jump into installation process. But this is just a quick win and later you will face again same issues (when next time you need to recaclculate lock file).
I was also getting the exactly 1610612736 bytes exhausted error and fixed it by running:
COMPOSER_MEMORY_LIMIT=-1 php -d memory_limt=-1 $(which composer) install
If that does not work, try renaming the composer.lock file and try again.
Allowed memory size of 1610612736 bytes exhausted (tried to allocate 83886080 bytes) in phar:///usr/local/bin/composer.phar/src/Composer/DependencyResolver/RuleSet.php on line 90
I fixed this by using this
COMPOSER_MEMORY_LIMIT=-1 composer require "Package Name"

Can not allocate memory error when install passport in laravel using composer

I am installing passport in laravel by composer using command
$ composer require laravel/passport
Using version ^6.0 for laravel/passport
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
mmap() failed: [12] Cannot allocate memory
mmap() failed: [12] Cannot allocate memory
Fatal error: Out of memory (allocated 483401728) (tried to allocate 8388608 bytes) in phar:///opt/cpanel/composer/bin/composer/src/Composer/DependencyResolver/Solver.php on line 220
I got above errors please help me if you have any solutions.
I was able to install Passport by temporarily removing PHP's memory limit. I found this idea here: https://laravel.io/forum/02-11-2014-composer-running-out-of-memory
$ php -d memory_limit=-1 /usr/local/bin/composer require laravel/passport --verbose --profile
I like this solution because it overrides the PHP limit only once, so it allows you to push forward without any lasting affects. This will allow you to wait and see if you continue to get issues later, such as in the production environment, etc.
The default PHP installation allocates 500 MB~ RAM I believe, and when I ran that above command, it consumed 712 MB of RAM.
Extra note
At that above URL, there is also mention of committing the composer.lock file in the production environment. Historically, it can be a concern if, for example, you are developing localmachine on MacOS or Windows and then your production environment is Linux. It might not be likely, but it is possible a person could experience issues due to arbitrary packages determining what dependencies to select based on the detected operating system. If you commit the lock file, you are caching the packages/versions. The performance benefits will stem from that, but caching breeds rigidity.
I'm not sure of the true likelihood of what I'm saying. I'm saying this about composer, but I've seen it with npm and JavaScript.
Try the following steps:
sudo fallocate -l 2G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
In the root of your project in the composer.json in the line of require "require": {"laravel/ui": "^1.1"} and next, composer update
Source
Memory limit errors.
Composer may sometimes fail on some commands with this message:
PHP Fatal error: Allowed memory size of XXXXXX bytes exhausted <...>
In this case, the PHP memory_limit should be increased.
Note: Composer internally increases the `memory_limit` to 1.5G.
To get the current memory_limit value, run:
php -r "echo ini_get('memory_limit').PHP_EOL;"
Try increasing the limit in your php.ini file (ex. /etc/php5/cli/php.ini for Debian-like systems):
Use -1 for unlimited or define an explicit value like 2G
memory_limit = -1
Composer also respects a memory limit defined by the COMPOSER_MEMORY_LIMIT environment variable:
COMPOSER_MEMORY_LIMIT=-1 composer.phar <...>
Or, you can increase the limit with a command-line argument:
php -d memory_limit=-1 composer.phar <...>
This issue can also happen on cPanel instances, when the shell fork bomb protection is activated. For more information, see the documentation of the fork bomb feature on the cPanel site.
This answer might also be useful.

PHP artisan "PHP Fatal error" on allowed memory size in Laravel

It's confusing, why this error shown. I'm using Laravel 5.4, after using composer update then this error shown.
$ composer update
Loading composer repositories with package information
Updating dependencies (including require-dev)
Nothing to install or update
Generating autoload files
> Illuminate\Foundation\ComposerScripts::postUpdate
> php artisan optimize
PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 495616 bytes) in E:\xampp\htdocs\botble\vendor\symfony\debug\ExceptionHandler.php on line 238
PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 4096 bytes) in E:\xampp\htdocs\botble\vendor\symfony\debug\Exception\FlattenException.php on line 203
Script php artisan optimize handling the post-update-cmd event returned with error code 255
As some of answer on stack and other community, i'm also test this after update php.ini with memory_limit 2048M. But still same error shown.
Any suggestion for this issue.
This is memory limit issue .
You can try something like this
Fist find composer directory using bellow command
$>which composer
/usr/local/bin/composer
After you can update composer with memory limit
$>php -d memory_limit=-1 /usr/local/bin/composer update
-1 means unlimited memory
In my case helped this
php -d memory_limit=1 artisan xxxxxxx

Strange Fatal error: Allowed memory size in composer file

i want to import a new bundle to my symfony project but i got this error :
Fatal error: Allowed memory size of 1073741824 bytes exhausted (tried to allocate 64 bytes) in phar://C:/ProgramData/ComposerSetup/bin/composer.phar/src/Composer/DependencyResolver/Rule.php on line 60
i've tried to update the memory_limits to -1
php -d memory_limit=-1 composer.phar update
message:
Nothing to install or update
i modified my composer.phar manually
same error.
Try to run: composer install first, sometimes the app contains some errors that creates a infinite loop, and that cause the memory problem. If you found any error, solve it, and try to run: composer update again.

Categories