我试图通过运行下面的命令将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


当前回答

要覆盖这个问题并在您的本地计算机上修复这个问题,您可以在php.ini配置文件中执行以下更改。

要找到您的php.ini配置文件,您可以使用以下命令

运行此命令后,您应该看到如下所示的输出:

Configuration File (php.ini) Path: /usr/local/etc/php/7.3
Loaded Configuration File:         /usr/local/etc/php/7.3/php.ini <---- note the path
Scan for additional .ini files in: /usr/local/etc/php/7.3/conf.d
Additional .ini files parsed:      /usr/local/etc/php/7.3/conf.d/ext-opcache.ini

我们想要更改的文件是Loaded Configuration。

打开并搜索memory_limit,可以将memory_limit = -1设置为PHP进程提供无限的内存,也可以设置512MB、1G、2G、5G、.... $ nano /usr/local/etc/php/7.3/php.ini

定位和设置:

$ memory_limit = -1 or memory_limit = 1G

保存文件后,您可以通过运行这个命令来验证PHP的更改,该命令将在您的PHP .ini文件中输出当前内存设置: php -r "echo ini_get('memory_limit').PHP_EOL;"

注意: 保存后,新的内存将工作。你不需要做任何其他事情。

更多信息:https://support.acquia.com/hc/en-us/articles/360036102614-Overriding-memory-limits-during-local-development-with-Composer

其他回答

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

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

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

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

跳过内存限制和版本错误使用下面的代码:

COMPOSER_MEMORY_LIMIT=-1 composer require <package-name> --ignore-platform-reqs

在我的情况下,当我得到这个错误时,我试图要求这个包。

你可以像这样运行,你不需要更新PHP INI文件:

COMPOSER_MEMORY_LIMIT=-1 composer require huddledigital/zendesk-laravel

Windows 10;

后藤C: \ ProgramData ComposerSetup \ bin

编辑:composer.bat并在最后一行添加memory_limit=-1,如下所示。

@echo OFF
:: in case DelayedExpansion is on and a path contains ! 
setlocal DISABLEDELAYEDEXPANSION
php -d memory_limit=-1 "%~dp0composer.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)