gpt4 book ai didi

php - Composer 总是遇到 "Allowed memory size of 1610612736 bytes exhausted"- 在服务器和本地

转载 作者:行者123 更新时间:2023-12-03 11:22:21 28 4
gpt4 key购买 nike

我在我的 Laravel 6 项目中使用 Composer 。但是,不知何故,我总是遇到问题“允许的内存大小为 1610612736 字节已用完”。我不知道为什么,但几天以来我遇到了这个问题,我不知道为什么或它来自哪里。
奇怪的是,我在开发服务器上遇到了完全相同的错误。这意味着它必须对 Laravel 项目本身做一些事情。因为正如我所说,在我的 Mac 和我的开发服务器上,我得到了完全相同的输出和完全相同的配置和项目。
唯一的解决方法是 php -d memory_limit=-1 composer update 。但是我无法在我的服务器上执行此操作,因为我不是服务器的管理员并且 RAM 使用量有限。所以,我确实想知道是什么导致了这个问题以及我如何解决这个问题。
除了下面的信息,您还需要更多信息吗?
我感谢任何形式的帮助!
亲切的问候和谢谢!
我的 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"
]
}
}

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/php@7.3/7.3.18_1/bin/php
OpenSSL version: OpenSSL 1.1.1g 21 Apr 2020

当我运行此命令时:
(基本上是我安装、删除或更新软件包的任何命令)
composer update
composer install
...
...
我得到以下输出:
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.

最佳答案

当 composer 检测到 PHP 内存限制过低时,它会自动将内存限制增加到 1.5 GB。对于某些依赖集,这可能仍然没有足够的内存。
您可以通过在 composer 命令中内联指定 COMPOSER_MEMORY_LIMIT 环境变量来增加单个 composer 命令的内存限制。您可以将其增加到特定值,也可以将其设置为 -1 以消除内存限制,这样它就会尽可能多地用完。 注意:这不会改变服务器上的任何内容。这只会影响 Composer 对这一命令的内存限制。

COMPOSER_MEMORY_LIMIT=-1 composer install
如果您在执行此命令后仍然遇到内存问题,因为您的系统没有足够的可用内存,或者您需要人为地限制您的内存使用(您提到您有“有限的 RAM 使用”),您可以尝试设置和使用交换文件以增加可用的内存量。
创建并启用临时交换文件:
# 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
现在,使用交换文件设置,运行您的 composer 命令。由于交换文件比 RAM 慢,这可能需要比您习惯的多一点时间。
完成 Composer 命令后,您可以根据需要禁用和删除交换文件。
# Disable the swap file
swapoff ~/.swapfile

# Remove the swap file.
rm ~/.swapfile

关于php - Composer 总是遇到 "Allowed memory size of 1610612736 bytes exhausted"- 在服务器和本地,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63658760/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com