Issue
There is a known issue with composer where when you try to use composer require
or composer update
you might see the following errors during local development:
PHP 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
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
Resolution
To override this and fix the issue on your local machine you can do the following changes within your php.ini
configuration file.
To locate your php.ini
configuration file you can use the following command: php --ini
After running this command you should see an output like the following:
Configuration File (php.ini) Path: /usr/local/etc/php/7.3
Loaded Configuration File: /usr/local/etc/php/7.3/php.ini
Scan for additional .ini files in: /usr/local/etc/php/7.3/conf.d
Additional .ini files parsed: /usr/local/etc/php/7.3/conf.d/ext-opcache.ini
The file we want to change is the Loaded Configuration File
When you open the file you can search for the memory_limit
setting and then update it accordingly. You can try to incrementally override this value and re-run your composer commands or alternatively, you can set the memory_limit = -1
to give an unlimited amount of memory to PHP processes.
After saving your file, you can verify the PHP changes by running this command which will output the current memory settings in your php.ini
file:
php -r "echo ini_get('memory_limit').PHP_EOL;"
For more information on this issue, you can view the documentation on Composer docs: