Home > Backend Development > PHP Tutorial > How to Fix Composer 'Allowed Memory Size Exhausted' Error During Package Installation?

How to Fix Composer 'Allowed Memory Size Exhausted' Error During Package Installation?

Susan Sarandon
Release: 2024-12-26 03:03:10
Original
199 people have browsed it

How to Fix Composer

Composer Require Memory Exhaustion: PHP Fatal Error "Allowed Memory Size Exhausted"

Problem:

Attempting to install HWIOAuthBundle using composer require leads to an out-of-memory error:

PHP Fatal error: Allowed memory size of 1610612736 bytes exhausted (tried to allocate 67108864 bytes)
Copy after login

despite increasing the memory_limit in php.ini to 2GB.

Solution:

To resolve this issue, try the following steps:

1. Check Current Memory Limit:

Run the command:

php -r "echo ini_get('memory_limit').PHP_EOL;"
Copy after login

2. Increase Memory Limit in php.ini:

Modify the php.ini file (e.g., /etc/php5/cli/php.ini for Debian-like systems) and set:

memory_limit = -1
Copy after login

3. Use Command-Line Argument:

Use the command-line argument to increase the limit:

php -d memory_limit=-1 composer.phar require hwi/oauth-bundle php-http/guzzle6-adapter php-http/httplug-bundle
Copy after login

4. Get php.ini Location:

To locate loaded php.ini files, run:

php --ini
Copy after login

5. Quick Solution Using Environment Variable:

Set the COMPOSER_MEMORY_LIMIT environment variable:

COMPOSER_MEMORY_LIMIT=-1 composer require hwi/oauth-bundle php-http/guzzle6-adapter php-http/httplug-bundle
Copy after login

The above is the detailed content of How to Fix Composer 'Allowed Memory Size Exhausted' Error During Package Installation?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template