-2

I have hit the error

Fatal error: Allowed memory size of 1610612736 bytes exhausted (tried to allocate 4096 bytes) in phar:///usr/local/bin/composer/src/Composer/DependencyResolver/RuleWatchGraph.php on line 52

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

While trying the code:

composer require laravel/passport

in my laravel project.

I have tried following the instructions in the link but I am unable to increase my memory limit because I cannot find the file php.ini in my /etc/ directory. I can only find php.ini.default and I have increased the memory limit there to 900MB. I have restarted apache for the new configuration to reflect but the limit still shows 128MB which is what it has always shown in when I run the command:

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

How can I get this fixed? My php version is 7.3.9

I must also mention that the issue I have is peculiar to a particular project. I have been able to successfully run

composer require laravel/passport

in another project

Maik Lowrey
  • 15,957
  • 6
  • 40
  • 79
mykoman
  • 1,715
  • 1
  • 19
  • 33
  • 2
    You might have more luck with `php -d memory_limit=-1 composer require laravel/passport` – aynber Apr 22 '20 at 13:07
  • If you want to find the loaded ini file, try running `php -r "echo php_ini_loaded_file(), PHP_EOL;"` – iainn Apr 22 '20 at 13:08
  • @aynber got the response Could not open input file: composer – mykoman Apr 22 '20 at 13:10
  • https://haydenjames.io/understanding-php-memory_limit/ – flakerimi Apr 22 '20 at 13:11
  • @iainn return nothing when I ran the command – mykoman Apr 22 '20 at 13:12
  • You might need `composer.phar` as mentioned in the instructions on the error page instead of just `composer` – aynber Apr 22 '20 at 13:14
  • @mykoman Hmm, that's strange. Try `php --ini`, it should give you some more information about where and what it's scanning at startup – iainn Apr 22 '20 at 13:14
  • @iainn here is the response Configuration File (php.ini) Path: /etc Loaded Configuration File: (none) Scan for additional .ini files in: (none) Additional .ini files parsed: (none) – mykoman Apr 22 '20 at 13:16
  • @aynber what should I do about the composer.phar ? – mykoman Apr 22 '20 at 13:18
  • The given message tells you that Composer already used more than 1.5GB of memory. Which version are you running? – Nico Haase Apr 22 '20 at 13:24
  • You would change the command to be `php -d memory_limit=-1 composer.phar require laravel/passport` – aynber Apr 22 '20 at 13:28
  • Actually, never mind. As mentioned in Nico's link, Composer automatically adjusts it's memory to be 1.5G. Your error message says 1610612736 bytes exhausted, which is 1.5G. How much memory is on the machine? – aynber Apr 22 '20 at 13:30

1 Answers1

-1

Try renaming the php.ini.default to php.ini. PHP doesn't load it if it has the .default extension. You can run php --ini in your console to see which ini files are loaded. Your php.ini should be in this list, otherwise just add the memory limit setting to another file in this list.

There can also be a case where there are two different ini configs, one for cli and one for web. If you have both make sure you're editing the correct one. If you've got php-fpm installed you'll most lkikely have a php.ini in /etc/php/7.3/fpm and /etc/php/7.3/cli.

If all of the above doesn't work you can always try to just reinstall your vendors:

  • delete your vendor folder
  • delete your composer.lock (composer's cache)
  • add the passport requirement manually to your composer.json (e.g. "laravel/passport": "^7.3")
  • and finally run composer install, installing everything again.
akalucas
  • 476
  • 3
  • 13
  • "Reinstall vendors" should never contain deleting `composer.lock` – Nico Haase Apr 22 '20 at 13:24
  • Care to explain? afaik composer just rebuilds the lock if it isn't there when you run an install. Rebuilding the lock requires less memory that adding a new requirement to an existing lock. Seeing how he was having a memory issue this would seem a valid option to try right? – akalucas Apr 22 '20 at 13:45
  • Of course: if you remove the lock file, you remove the information about all currently installed packages. On rebuilding the lock, all packages will be installed using the latest possible versions (according to the rules given in composer.json), while installing a single package will not update any other package – Nico Haase Apr 22 '20 at 13:47
  • Also, why should calculating the versions for **all** packages consume less memory than the smaller subset needed for a single package? – Nico Haase Apr 22 '20 at 13:47
  • During which composer needs to cross reference compatibility over the installed and the new versions of packages. – akalucas Apr 22 '20 at 13:49
  • Just telling what has worked for me in the past :) – akalucas Apr 22 '20 at 13:49