-1

I was trying to install intervention/image into my Laravel project by using the command "composer require intervention/image" in command prompt. However an error message showed saying "Out of memory". Does anybody know how to solve this problem?

My Laravel version is 7.15.0.

Any help would be appreciated as I have tried multiple methods with no success.

Thank you in advance.

toyop
  • 99
  • 1
  • 1
  • 11
  • What version of Composer are you using? – Rwd Apr 11 '21 at 11:14
  • Hey there, I'm using Composer version 1.10.6 – toyop Apr 11 '21 at 12:32
  • I would suggest trying to upgrade to V2: `composer selfupdate --2`. You should be able to rollback to version 1 with `composer selfupdate --1` at any time. – Rwd Apr 11 '21 at 14:07
  • 1
    Hi, updating composer did the trick. Thank you so much! If you could write the solution in the answer section I will choose you as the best answer. – toyop Apr 12 '21 at 07:45

2 Answers2

0

Composer expects the memory limit set default by the PHP Apache Server for installing the additional dependencies. Therefor, if any dependency exceeds the limit it terminates the installation. Therefore, we have to set this limit to unlimited by setting the flag to -1

export COMPOSER_MEMORY_LIMIT=-1 composer require intervention/image

or

php -d memory_limit=-1 composer require intervention/image
Wahyu Kristianto
  • 8,719
  • 6
  • 43
  • 68
Muhammad Atif Akram
  • 1,204
  • 1
  • 4
  • 12
  • 1
    Please could you add a quick explanation of what the above does :) – Rwd Apr 11 '21 at 11:21
  • Dear @Rwd Composer expects the memory limit set default by the PHP Apache Server for installing the additional dependencies. Therefor, if any dependency exceeds the limit it terminates the installation. Therefore, we have to set this limit to unlimited by setting the flag to -1 – Muhammad Atif Akram Apr 11 '21 at 11:25
  • Hey there, Thank you for your replies. What should I do when I get this message. "'COMPOSER_MEMORY_LIMIT' is not recognized as an internal or external command,". – toyop Apr 11 '21 at 11:42
  • are you sure composer is installed globally. You may verify by running following command. composer --version – Muhammad Atif Akram Apr 11 '21 at 11:44
  • Hi, it shows this message"Composer version 1.10.6 2020-05-06 10:28:10". – toyop Apr 11 '21 at 11:52
  • I think you are on windows. Please refer to this thread for windows . https://stackoverflow.com/questions/62594926/how-to-solve-memory-limit-and-composer-errors-in-laravel-project – Muhammad Atif Akram Apr 11 '21 at 12:04
0

I would recommend updating Composer to version 2 as it introduces numerous improvements (which can be found here). One of the improvements is:

"...downloading files in parallel using curl and constraint evaluation optimizations"

This leads to massive improvements for memory usage.

Updating

composer selfupdate --2

If you run in to issues or you need to rollback:

composer selfupdate --1
Rwd
  • 34,180
  • 6
  • 64
  • 78