PHP Fatal error: Allowed memory size of 1610612736 bytes exhausted (tried to allocate 4096 bytes)

Auth:猫饭       Date:2021/10/8       Cat:代码       Word:共1213字       Views:38

今天在使用composer安装扩展包时报错,如下:

PHP Fatal error:  Allowed memory size of 1610612736 bytes exhausted (tried to allocate 4096 bytes) in phar:///www/server/php/74/bin/composer/src/Composer/DependencyResolver/Solver.php on line 223

Fatal error: Allowed memory size of 1610612736 bytes exhausted (tried to allocate 4096 bytes) in phar:///www/server/php/74/bin/composer/src/Composer/DependencyResolver/Solver.php on line 223

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

PHP Fatal error: Allowed memory size of 1610612736 bytes exhausted (tried to allocate 4096 bytes) - 第1张图片 于是折腾了很久,终于还是成功了,写下文章记录一下,分享给大家。

在网上找到的文章如下,

通过上面提示composer链接,输出内存配置信息

php -r "echo ini_get('memory_limit').PHP_EOL;"
输出 128M

我尝试修改 php.ini文件,我的路径是 /etc/php7/apache2/php.ini,修改里面的 memory_limit = -1, 重启apache之后,运行 composer update 一样的错误,我想到的是可能 php 命令和apache2的 php.ini文件不是同一个,所以

wakasann@linux-2ywt:/srv/www/htdocs/sfs> sudo find / -name "php.ini"[sudo] password for root: /etc/php7/cli/php.ini/etc/php7/apache2/php.ini/etc/php7/fastcgi/php.ini
我尝试修改 /etc/php7/cli/php.ini 中的 memory_limit的值为 -1,修改完之后,运行

php -r "echo ini_get('memory_limit').PHP_EOL;"
输出结果是: -1 感觉修改成功,composer update也可正常运行了。

可以成功解决,但是不安全,在这里不推荐使用。

终极解决方法

这里写下我的推荐方法,就是使用命令安装。

php -d memory_limit=-1 /usr/bin/composer require xxxx/xxxxxxx

就可以发现安装成功了。 PHP Fatal error: Allowed memory size of 1610612736 bytes exhausted (tried to allocate 4096 bytes) - 第2张图片

注意

上述命令中的/usr/bin/composer,为composer安装地址 可使用 composer -h 命令进行获取。

PHP Fatal error: Allowed memory size of 1610612736 bytes exhausted (tried to allocate 4096 bytes) - 第3张图片

除非注明,猫饭文章均为原创,本文地址 https://maofun.com/1878.html,转载请以链接形式注明出处。

作者: 简介:

《PHP Fatal error: Allowed memory size of 1610612736 bytes exhausted (tried to allocate 4096 bytes)》留言数:0

发表留言