前言

今天使用 composer 更新安装扩展包的时候,报超出内存大小的提示

Fatal error: Allowed memory size of 1610612736 bytes exhausted (tried to allocate 4096 bytes) in phar://C:/ProgramData/ComposerSetup/bin/composer.phar/src/Composer/DependencyResolver/Rule2Literals.php on li
ne 53

Check https://getcomposer.org/doc/articles/troubleshooting.md#memory-limit-errors for more info on how to handle out of memory errors.

解决方法

首先执行 composer 帮助命令,获取 composer 安装目录

composer -h

执行结果

D:\php_work\fund-admin>composer -h
Usage:
help [options] [--] [<command_name>]

Arguments:
command The command to execute
command_name The command name [default: "help"]

Options:
--xml To output help as XML
--format=FORMAT The output format (txt, xml, json, or md) [default: "txt"]
--raw To output raw command help
-h, --help Display this help message
-q, --quiet Do not output any message
-V, --version Display this application version
--ansi Force ANSI output
--no-ansi Disable ANSI output
-n, --no-interaction Do not ask any interactive question
--profile Display timing and memory usage information
--no-plugins Whether to disable plugins.
-d, --working-dir=WORKING-DIR If specified, use the given directory as working directory.
--no-cache Prevent use of the cache
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

Help:
The help command displays help for a given command:

php C:\ProgramData\ComposerSetup\bin\composer.phar help list

You can also output the help in other formats by using the --format option:

php C:\ProgramData\ComposerSetup\bin\composer.phar help --format=xml list

To display the list of available commands, please use the list command.

可以看到 ​​C:\ProgramData\ComposerSetup\bin\composer.phar​​ 为我的composer安装目录

这时候安装扩展命令修改为

# php -d memory_limit=-1 php程序设置内存无限制
# C:\ProgramData\ComposerSetup\bin\composer.phar composer安装地址
# require dcat/laravel-admin:"2.*" -vvv 载入扩展包
php -d memory_limit=-1 C:\ProgramData\ComposerSetup\bin\composer.phar require dcat/laravel-admin:"2.*" -vvv