我试图通过运行下面的命令将HWIOAuthBundle添加到我的项目中。

composer require hwi/oauth-bundle php-http/guzzle6-adapter php-http/httplug-bundle

HWIOAuthBundle github: https://github.com/hwi/HWIOAuthBundle

当我试图运行作曲家要求,我得到了内存错误。

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

我尝试在我的php.ini文件中设置内存限制为2G,但没有工作。我找到我的php.ini通过运行php -i | grep php.ini


当前回答

以防你得到一个作曲家错误:

无法打开输入文件:composer

run:

php -d memory_limit=-1 /usr/local/bin/composer require ...

其他回答

我已经绕过了Homestead Laravel(流浪)虚拟机运行composer命令之前的COMPOSER_MEMORY_LIMIT=-1的问题:

例子

要更新Composer:

COMPOSER_MEMORY_LIMIT=-1 composer update

安装软件包:

COMPOSER_MEMORY_LIMIT=-1 composer require spatie/laravel-translatable

如果增加内存限制没有帮助或您没有太多内存

在另一台高内存的机器上

将composer的内存限制设置为-1 删除作曲家。锁文件 运行composer install 提交作曲家。锁定文件到您的回购 然后在服务器上运行composer install

这个想法是在计算/创建composer时使用了大部分内存。锁文件,如果它的创建/就绪- composer安装将不会使用太多内存。

您可以在运行Composer时使用特定的php版本

如果像我一样,由于某种原因,尽管您的计算机是64位的,但您使用的是32位的PHP,这将总是限制分配给Composer的内存数量。我是这样解决问题的:

在你的电脑上安装一个64位的php版本(比如在C:/php64中) 在composer中(在我的例子中使用cygwin)运行:

C:/php64/php.exe ../作曲家。phar更新

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_limit to -1 works for me;) (vim /etc/php/7.2/cli/php.ini)

在我的情况下,我试图安装Laravel框架没有说明xampp服务器(或apache服务器)在我的windows系统,我得到以下错误

致命错误:允许的1610612736字节内存耗尽

当我启动xampp服务器(或apache服务器)时,它就开始安装laravel框架,错误就消失了。

所以有时候你必须检查这个,否则它会比平时花费更长的时间,消耗更多的内存,结果大小会被耗尽。