Reputation: 582
I am using composer on my Laravel 6 project. However, somehow I always run into the problem is "Allowed memory size of 1610612736 bytes exhausted". I don't know why but since a few days I have this problem and I don't know why or where it does come from.
The curios thing is that I get exactly the same error on my development server. That means it must has to do something with the Laravel project itself. Because as I said, on my Mac as well as on my development server I get the exact same output with exact the same config and project.
The only workaround is php -d memory_limit=-1 composer update
. But I cannot do this on my server because I am not the admin of the server and have a limited RAM usage. So, I do want to know what is causing this problem and how I can solve this.
Do you need any more information then those below? I appreciate any kind of help!
Kind regards and thank you!
My composer.json
:
{
"name": "laravel/laravel",
"type": "project",
"description": "The Laravel Framework.",
"keywords": [
"framework",
"laravel"
],
"license": "MIT",
"repositories": [
{
"type": "composer",
"url": "https://nova.laravel.com"
}
],
"require": {
"php": "^7.2",
"components/jquery": "^3.4",
"cybercog/laravel-nova-ban": "^1.1",
"emilianotisato/nova-tinymce": "^1.1",
"fideloper/proxy": "^4.0",
"glorand/laravel-model-settings": "^3.5",
"inspheric/nova-indicator-field": "^1.43",
"kabbouchi/nova-logs-tool": "^0.2.0",
"laravel/framework": "^6.2",
"laravel/nova": "~2.0",
"laravel/socialite": "^4.4",
"laravel/telescope": "^3.0",
"laravel/tinker": "^1.0",
"laravel/ui": "^1.1",
"laravelcollective/html": "^6.1",
"llaski/nova-scheduled-jobs": "^3.0",
"mad-web/nova-telescope-link": "^3.0",
"orangehill/iseed": "^2.6",
"paquettg/php-html-parser": "^2.1",
"pdewit/nova-external-url": "^1.0",
"phpunit/php-code-coverage": "^9.1",
"phpunit/phpunit": "^9.2",
"spatie/laravel-honeypot": "^1.4",
"spatie/laravel-medialibrary": "^7.19",
"spatie/laravel-permission": "^3.2",
"twbs/bootstrap": "^4.3",
"vyuldashev/nova-permission": "^2.9",
"yoeunes/toastr": "^1.2"
},
"require-dev": {
"barryvdh/laravel-debugbar": "^3.2",
"barryvdh/laravel-ide-helper": "^2.6",
"brianium/paratest": "^4.1",
"facade/ignition": "^1.4",
"fzaninotto/faker": "^1.4",
"mockery/mockery": "^1.0",
"nunomaduro/collision": "^3.0"
},
"config": {
"optimize-autoloader": true,
"preferred-install": "dist",
"sort-packages": true
},
"extra": {
"laravel": {
"dont-discover": []
}
},
"autoload": {
"psr-4": {
"App\\": "app/"
},
"classmap": [
"database/seeds",
"database/factories"
],
"files": [
"app/Helpers/helper.php",
"app/Helpers/commentsHelper.php"
]
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
"minimum-stability": "dev",
"prefer-stable": true,
"scripts": {
"post-autoload-dump": [
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
"@php artisan package:discover --ansi"
],
"post-root-package-install": [
"@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"@php artisan key:generate --ansi"
],
"post-update-cmd": [
"Illuminate\\Foundation\\ComposerScripts::postUpdate",
"@php artisan ide-helper:generate",
"@php artisan ide-helper:meta"
]
}
}
Output of composer diagnose
:
Checking composer.json: OK
Checking platform settings: OK
Checking git settings: OK
Checking http connectivity to packagist: OK
Checking https connectivity to packagist: OK
Checking github.com rate limit: OK
Checking disk free space: OK
Checking pubkeys:
Tags Public Key Fingerprint: 57815BA2 7E54DC31 7ECC7CC5 573090D0 87719BA6 8F3BB723 4E5D42D0 84A14642
Dev Public Key Fingerprint: 4AC45767 E5EC2265 2F0C1167 CBBB8A2B 0C708369 153E328C AD90147D AFE50952
OK
Checking composer version: OK
Composer version: 1.10.10
PHP version: 7.3.18
PHP binary path: /usr/local/Cellar/[email protected]/7.3.18_1/bin/php
OpenSSL version: OpenSSL 1.1.1g 21 Apr 2020
When I run this command:
(Basically any commands where I install, remove or update packages)
composer update
composer install
...
...
I get the following output:
PHP Fatal error: Allowed memory size of 1610612736 bytes exhausted (tried to allocate 4096 bytes) in phar:///usr/local/Cellar/composer/1.10.7/bin/composer/src/Composer/DependencyResolver/Solver.php on line 223
Fatal error: Allowed memory size of 1610612736 bytes exhausted (tried to allocate 4096 bytes) in phar:///usr/local/Cellar/composer/1.10.7/bin/composer/src/Composer/DependencyResolver/Solver.php on line 223
Check https://getcomposer.org/doc/articles/troubleshooting.md#memory-limit-errors for more info on how to handle out of memory errors.
Upvotes: 9
Views: 18639
Reputation: 10350
Simply set the composer memory limit to none by prefixing COMPOSER_MEMORY_LIMIT=-1
as following:
COMPOSER_MEMORY_LIMIT=-1 composer create-project laravel/laravel project-name
Noted that, you should replace project-name
with your expected name.
Upvotes: 0
Reputation: 405
If none of the above solve. try this: check php memory (in command line):
php -r "echo ini_get('memory_limit').PHP_EOL;"
check loaded php.ini for cli:
php -r "phpinfo();"
it should show something like /etc/php/7.4/cli/php.ini
now change the above ini file with memory_limit above 1.5G (since composer will automatically scale memory upto 1.5 G)
memory_limit = 2024M
restart nginx :
sudo service nginx restart
once again check php memory whether increased:
php -r "echo ini_get('memory_limit').PHP_EOL;"
Upvotes: 3
Reputation: 15765
It is happening due to limited memory allocated to PHP. Check in the php.ini
Following is one of the ways to resolve this
php -d memory_limit=-1 /usr/local/bin/composer update
Upvotes: 1
Reputation: 62338
When composer detects the PHP memory limit is too low, it automatically increases the memory limit to 1.5 GB. For some dependency sets, this still may not be enough memory.
You can increase the memory limit for a single composer command by specifying the COMPOSER_MEMORY_LIMIT
environment variable inline in the composer command. You can increase it to a specific value, or you can set it to -1
to remove the memory limit, so it'll use up as much as is available. Note: this does not change anything on the server. This only affects the memory limit for composer for this one command.
COMPOSER_MEMORY_LIMIT=-1 composer install
If you still run into memory issues after this command because your system doesn't have enough memory available, or you need to artificially limit your memory usage (you mentioned you have "limited RAM usage"), you can attempt to setup and use a swap file to boost the amount of memory available to you.
Create and enable a temporary swap file:
# Create a 2GiB (1024x2M) empty file at ~/.swapfile
# This may take a minute.
dd if=/dev/zero of=~/.swapfile bs=1024 count=2M
# Setup a swap area in the new empty file.
mkswap ~/.swapfile
# Enable the swap area in the file (temporary - does not survive reboot).
swapon ~/.swapfile
Now, with the swap file setup, run your composer commands. This may take a little more time than you're used to, since swap files are slower than RAM.
Once you're done with your composer commands, you can disable and remove the swap file, if you'd like.
# Disable the swap file
swapoff ~/.swapfile
# Remove the swap file.
rm ~/.swapfile
Upvotes: 9
Reputation: 1888
Composer can consume a lot of memory at times when updating or installing new modules/plugins.
Update the composer to latest version
php composer.phar --self-update
Then increase the composer memory limit in the environment variable
COMPOSER_MEMORY_LIMIT=512MB php composer.phar update
512MB is the new limit. You can edit as required by your system. Read more here
Upvotes: 1