Composer 需要内存不足。PHP 致命错误:允许的内存大小为 1610612736 字节已用完
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/49212475/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Composer require runs out of memory. PHP Fatal error: Allowed memory size of 1610612736 bytes exhausted
提问by Brian Chen
I am trying to add HWIOAuthBundle to my project by running the below command.
我正在尝试通过运行以下命令将 HWIOAuthBundle 添加到我的项目中。
composer require hwi/oauth-bundle php-http/guzzle6-adapter php-http/httplug-bundle
HWIOAuthBundle github: https://github.com/hwi/HWIOAuthBundle
HWIOAuthBundle github:https: //github.com/hwi/HWIOAuthBundle
When I try to run composer require I am getting the out of memory error.
当我尝试运行 composer require 时出现内存不足错误。
Using version ^0.6.0@dev for hwi/oauth-bundle Using version ^1.2@dev for php-http/guzzle6-adapter Using version ^1.10@dev for php-http/httplug-bundle ./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 67108864 bytes) in phar:///usr/local/Cellar/composer/1.4.2/libexec/composer.phar/src/Composer/DependencyResolver/Solver.php on line 220
Fatal error: Allowed memory size of 1610612736 bytes exhausted (tried to allocate 67108864 bytes) in phar:///usr/local/Cellar/composer/1.4.2/libexec/composer.phar/src/Composer/DependencyResolver/Solver.php on line 220
使用版本 ^0.6.0@dev for hwi/oauth-bundle 使用版本 ^1.2@dev for php-http/guzzle6-adapter 使用版本 ^1.10@dev for php-http/httplug-bundle ./composer.json 已更新使用包信息加载 Composer 存储库 更新依赖项(包括 require-dev)
PHP 致命错误:在 phar:///usr/local/Cellar/composer/1.4.2/libexec/composer.phar/src/Composer/DependencyResolver/Solver 中,允许的内存大小为 1610612736 字节(试图分配 67108864 字节)。 php 在线 220
致命错误:在 phar:///usr/local/Cellar/composer/1.4.2/libexec/composer.phar/src/Composer/DependencyResolver/Solver.php 中允许的内存大小为 1610612736 字节(试图分配 67108864 字节)在线 220
I tried setting the memory_limit to 2G in my php.ini file but did not work. I found my php.ini by running php -i | grep php.ini
我尝试在我的 php.ini 文件中将 memory_limit 设置为 2G,但没有奏效。我通过运行找到了我的 php.iniphp -i | grep php.ini
回答by Adam
To get the current memory_limit value, run:
要获取当前的 memory_limit 值,请运行:
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):
尝试增加php.ini
文件中的限制(例如,/etc/php5/cli/php.ini
对于类 Debian 的系统):
; Use -1 for unlimited or define an explicit value like 2G
memory_limit = -1
Or, you can increase the limit with a command-line argument:
或者,您可以使用命令行参数增加限制:
php -d memory_limit=-1 composer.phar require hwi/oauth-bundle php-http/guzzle6-adapter php-http/httplug-bundle
To get loaded php.ini files location try:
要获取加载的 php.ini 文件位置,请尝试:
php --ini
回答by Thomas Vangelooven
回答by odubah
In my case I was trying to require this package, and I was getting the PHP Fatal error: Allowed memory size of
.
在我的情况下,我试图要求这个包,我得到了PHP Fatal error: Allowed memory size of
.
I found it easy to run like this and you don't have to update the PHP INI file.
我发现像这样运行很容易,而且您不必更新 PHP INI 文件。
example: COMPOSER_MEMORY_LIMIT=-1 composer require huddledigital/zendesk-laravel
例子: COMPOSER_MEMORY_LIMIT=-1 composer require huddledigital/zendesk-laravel
Hope this help someone.
希望这有助于某人。
回答by Aitor Fernandez
Just set the memory_limit
specifying the full route of your composer.phar file and update, in my case with the command:
只需设置memory_limit
指定 composer.phar 文件的完整路径并更新,在我的情况下使用命令:
php -d memory_limit=-1 C:/wamp64/composer.phar update
回答by Ruben Gonzalez
It was recently identified that Composer consumes high CPU + memory on packages that have a lot of historical tags. See composer/composer#7577
最近发现 Composer 在具有大量历史标签的包上消耗高 CPU + 内存。见作曲家/作曲家#7577
A workaround to this problem is using symfony/flex
or https://github.com/rubenrua/symfony-clean-tags-composer-plugin
此问题的解决方法是使用symfony/flex
或https://github.com/rubenrua/symfony-clean-tags-composer-plugin
composer global require rubenrua/symfony-clean-tags-composer-plugin
回答by Digital Human
On Windows 10;
在 Windows 10 上;
Goto C:\ProgramData\ComposerSetup\bin
转到 C:\ProgramData\ComposerSetup\bin
Edit: composer.bat
编辑:composer.bat
@echo OFF
:: in case DelayedExpansion is on and a path contains !
setlocal DISABLEDELAYEDEXPANSION
php -d memory_limit=-1 "%~dp0composer.phar" %*
Problem solved ;)
问题解决了 ;)
回答by Arno van Oordt
Since none of the previous answers included set
it took me a bit to figure out how to do it in Windows without altering the php.ini, but here's what worked for me:
由于以前的答案都没有包括在内,set
因此我花了一些时间才弄清楚如何在不更改 php.ini 的情况下在 Windows 中执行此操作,但以下是对我有用的方法:
set COMPOSER_MEMORY_LIMIT=-1
composer require hwi/oauth-bundle php-http/guzzle6-adapter php-http/httplug-bundle
回答by Marcus Christiansen
Just in case you get a composer error with:
以防万一您遇到 Composer 错误:
Could not open input file: composer
无法打开输入文件:作曲家
run:
跑:
php -d memory_limit=-1 /usr/local/bin/composer require ...
回答by Ted Mosby
Fatal error: Allowed memory size of 1610612736 bytes exhausted (tried to allocate 4096 bytes) in phar:///usr/local/bin/composer/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.
set memory_limitto -1works for me ;) (vim /etc/php/7.2/cli/php.ini)
将memory_limit设置为-1对我有用;) (vim /etc/php/7.2/cli/php.ini)
回答by Roubi
You can use a specific php Versionwhen running Composer
您可以在运行Composer时使用特定的 php 版本
If, like me, for some reason, you are using PHP 32 bitseven though your computer is 64 bits, this will always limit the amount of memory allocated to Composer. I solved my problem this way:
如果像我一样,出于某种原因,即使您的计算机是 64 位,您也使用PHP 32位,这将始终限制分配给 Composer 的内存量。我这样解决了我的问题:
- Install a 64 bits php version somewhere on your computer (let's say in C:/php64)
- In composer (using cygwin in my case), run:
- 在您的计算机上的某处安装 64 位 php 版本(假设在 C:/php64 中)
- 在作曲家(在我的例子中使用 cygwin)中,运行:
COMPOSER_MEMORY_LIMIT=-1 C:/php64/php.exe ../composer.phar update
COMPOSER_MEMORY_LIMIT=-1 C:/php64/php.exe ../composer.phar update