php - Composer : Allowed memory size error when installing package

标签 php composer-php

当我跑 composer require yab/laravel-scout-mysql-driver这是我得到的输出:

Using version ^2.40 for yab/laravel-scout-mysql-driver
./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 4096 bytes) in phar:///usr/local/Cellar/composer/1.3.2/libexec/composer.phar/src/Composer/DependencyResolver/RuleWatchGraph.php on line 52

Fatal error: Allowed memory size of 1610612736 bytes exhausted (tried to allocate 4096 bytes) in phar:///usr/local/Cellar/composer/1.3.2/libexec/composer.phar/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.

我正在运行 Composer 1.9.2。

这是我使用 -vvv 时输出的最后几行:
Reading /Users/redacted/.composer/cache/repo/https---repo.packagist.org/provider-ircmaxell$password-compat.json from cache
Reading /Users/redacted/.composer/cache/repo/https---repo.packagist.org/provider-paragonie$constant-time-encoding.json from cache
Reading /Users/redacted/.composer/cache/repo/https---repo.packagist.org/provider-yab$laravel-scout-mysql-driver.json from cache
Reading /Users/redacted/.composer/cache/repo/https---repo.packagist.org/provider-symfony$class-loader.json from cache
Reading /Users/redacted/.composer/cache/repo/https---repo.packagist.org/provider-symfony$polyfill-apcu.json from cache
Reading /Users/redacted/.composer/cache/repo/https---repo.packagist.org/provider-symfony$polyfill-xml.json from cache
Reading /Users/redacted/.composer/cache/repo/https---repo.packagist.org/provider-gecko-packages$gecko-php-unit.json from cache
PHP Fatal error:  Allowed memory size of 1610612736 bytes exhausted (tried to allocate 4096 bytes) in phar:///usr/local/Cellar/composer/1.3.2/libexec/composer.phar/src/Composer/DependencyResolver/RuleWatchGraph.php on line 52

Fatal error: Allowed memory size of 1610612736 bytes exhausted (tried to allocate 4096 bytes) in phar:///usr/local/Cellar/composer/1.3.2/libexec/composer.phar/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.

我的内存限制是 128M。 https://getcomposer.org/doc/articles/troubleshooting.md#memory-limit-errors除了增加我的内存限制之外,似乎没有提供很多见解,但似乎 128M 应该足够了?
php -d memory_limit=-1 /usr/local/bin/composer require yab/laravel-scout-mysql-driver没有帮助 - 我收到了“允许的内存大小为 1610612736 字节用尽”错误。与 memory_limit=1024M 相同.

我做了 php --ini并从中得到 /usr/local/etc/php/7.1/php.ini ,我对其进行了编辑以将内存限制更改为 1024MB 并得到相同的结果:“允许的内存大小为 1610612736 字节”。

奇怪的是,“允许的内存大小”在每个实例中都完全相同。就像我所做的实际上没有改变内存大小。

有任何想法吗?

最佳答案

(可能是) Composer Update failed -- out of memory 的重复
我在相同版本(PHP 7.1,Composer 1.9.x)和完全相同的内存限制(经过调查后在 Composer 中编码/定义)遇到了同样的问题。
所以,当你遇到这种错误时要做的第一件事就是告诉 Composer 不要用变量来限制内存,像这样:COMPOSER_MEMORY_LIMIT=-1 composer require "xxx/yyy"这是推荐的方式,但有时它是行不通的。
在我的项目中,似乎每次我执行 composer require xxx 时,composer.lock 都会损坏。 .
所以为了“修复”它,我这样做:

  • 删除您的 vendor文件夹 ( rm -fr vendor )
  • 删除 composer.lock ( rm composer.lock )
  • 确保您的 composer.json包含您的新需求(它应该在那里,因为之前的 composer require ),如果没有,添加它
  • 做一个新鲜的composer install

  • 此时,要么您将清楚地看到依赖项问题,要么将安装所有内容。
    我成功地做到了 2 次。

    关于php - Composer : Allowed memory size error when installing package,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59978196/

    相关文章:

    php - 如何在运行 'composer update/install' 后正确更改 composer 或 Symfony2 的功能?

    ssh - Satis - ssh2.sftp 协议(protocol)出错

    php - 合并来自两个 PDO 查询的结果

    php - 在 CakePHP 中一次存储多行

    php - 我如何判断当前交易是否会改变任何符合 Doctrine 2 的实体?

    javascript - 如何从一个子for​​each中获取值并将其放入父循环并随机排列数组中的所有值

    Yii2全新安装: vendor/bower/jquery/dist path is wrong

    php - 在 Laravel 中安全地编辑第三方 Composer (供应商)包并防止在发布新版本包时丢失自定义更改

    php - Composer 安装错误 "Could not parse URElasticsearch\Common\Exceptions\InvalidArgumentException : Could not parse URII"

    php - vagrant homestead无法访问主机(laravel 5.2)