Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Composer always runs into "Allowed memory size of 1610612736 bytes exhausted" - on server as well as local

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.
like image 254
Jan Avatar asked Aug 30 '20 14:08

Jan


People also ask

How do I fix the allowed memory size 1610612736 bytes exhausted?

Allowed memory size of 1610612736 bytes exhausted ??? can someone help me this? Try prefixing your command with COMPOSER_MEMORY_LIMIT=-1 . This will remove the memory limit for the execution of the command.

How do I change my memory limit on composer?

Use the format “128M” for megabyte or “2G” for gigabyte. You can use the value “-1” to ignore the memory limit completely. Another way would be to increase the PHP memory limit: php -d memory_limit=512M composer.

How do I fix the allowed memory size 134217728 bytes exhausted?

You simply have the code ini_set('memory_limit', '128M'); (or whatever your desired allocation is). You can remove the memory limit (although machine or instance limits may still apply) by setting the value to "-1".


2 Answers

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
like image 200
patricus Avatar answered Sep 26 '22 09:09

patricus


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;"
like image 37
user170851 Avatar answered Sep 22 '22 09:09

user170851