Home >Backend Development >PHP Tutorial >How to Fix 'Allowed memory size exhausted' Error During Composer Require?

How to Fix 'Allowed memory size exhausted' Error During Composer Require?

Patricia Arquette
Patricia ArquetteOriginal
2024-12-02 10:45:131019browse

How to Fix

Exceeding Memory Limit During Composer Require Operation: PHP Fatal Error

When executing composer require, users may encounter the following error:

PHP Fatal error: Allowed memory size of 1610612736 bytes exhausted (tried to allocate 67108864 bytes) in .../composer.phar/src/Composer/DependencyResolver/Solver.php on line 220

This indicates that Composer has run out of memory while attempting to resolve dependencies. To address this, several solutions are available:

1. Increase Memory Limit in php.ini

  • Determine the current memory limit: php -r "echo ini_get('memory_limit').PHP_EOL;"
  • Modify php.ini to increase the limit, e.g.:

    memory_limit = -1  // Unlimited
    or
    memory_limit = 2G // 2 Gigabytes

2. Set Memory Limit Using Command-Line Argument

php -d memory_limit=-1 composer.phar require <package1> <package2> ...

3. Check Loaded php.ini Files

php --ini

4. Set Environment Variable

COMPOSER_MEMORY_LIMIT=-1 composer require <package1> <package2> ...

5. Use composer.phar Flag (Alternative Method)

composer.phar COMPOSER_MEMORY_LIMIT=-1 require <package1> <package2> ...

6. Other Quick Solutions

  • php composer.phar COMPOSER_MEMORY_LIMIT=-1 require <package1> <package2> ...
  • COMPOSER_MEMORY_LIMIT=-1 composer require <package1> <package2> ...

When adjusting the memory limit, it is recommended to start with a reasonable value (e.g., 2G) and gradually increase it as needed. Also, check if there are any unnecessary dependencies or plugins that may consume excessive memory.

The above is the detailed content of How to Fix 'Allowed memory size exhausted' Error During Composer Require?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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