Composer update memory limit
When you run composer update
, the OS will look into the configured paths and try to locate an executable file with that name.
When running php composer update
, the composer
string is treated as a parameter to PHP, which is not searched in any paths. You have to provide the full path in order to run it.
Running which composer
will tell you where the OS finds the composer executable, and then you simply use the full path in the PHP command:
$>which composer
/usr/local/bin/composer
$>php -d memory_limit=512M /usr/local/bin/composer update
...
Note that 512MB might be too few. My perception is that it will happily take 1GB or more, depending on the number of dependencies you use and the variety of versions that you theoretically allow, i.e. if you allow Symfony ~2.3
, then you make Composer deal with a lot more possible versions compared to using ~2.7
.
Also note that running Composer on the production machine is not the best idea. You would have to have access to Github, maybe provide access credentials, have VCS tools installed, and you will easily break your site if any of the remote hosting servers is offline during your update. It is a better idea to use Composer on a deployment system that does all the preparation, and then moves all the files onto the production server.
Update
It's the year 2020 now, and the way Composer manages its memory has changed quite a bit. The most important thing is that Composer will increase the memory limit by itself if it encounters a limit set too low. This however immediately triggers the problem of running out of memory on machines that have too few memory installed. You can make Composer use less memory by setting the environment variable like COMPOSER_MEMORY_LIMIT=512M
, but this will create problems if Composer would need more memory to correctly operate.
My main point remains true: Do not run Composer on machines that have too few memory installed. You potentially need 1.5 GB of free memory to be able to update everything.
Composer require runs out of memory. PHP Fatal error: Allowed memory size of 1610612736 bytes exhausted
To get the current memory_limit value, run:
php -r "echo ini_get('memory_limit').PHP_EOL;"
Try increasing the limit in your php.ini
file (ex. /etc/php5/cli/php.ini
for Debian-like systems):
; Use -1 for unlimited or define an explicit value like 2G
memory_limit = -1
Or, you can increase the limit with a command-line argument:
php -d memory_limit=-1 composer.phar require hwi/oauth-bundle php-http/guzzle6-adapter php-http/httplug-bundle
To get loaded php.ini files location try:
php --ini
Another quick solution:
php composer.phar COMPOSER_MEMORY_LIMIT=-1 require hwi/oauth-bundle php-http/guzzle6-adapter php-http/httplug-bundle
Or just:
COMPOSER_MEMORY_LIMIT=-1 composer require hwi/oauth-bundle php-http/guzzle6-adapter php-http/httplug-bundle
Composer Update failed -- out of memory
Solved by deleting the whole vendor folder, and then doing the composer update again, and it works... somehow. I don't even understand :v
Increasing memory limit composer
Based on the document, you should be able to add a composer command in the <...>
php -d memory_limit=-1 composer <...>
So, for things like
php -d memory_limit=-1 composer require apackage
php -d memory_limit=-1 composer update
That means to run the composer command with memory_limit = -1.
PHP Fatal error: Allowed memory size of 1610612736 bytes composer update
Run
which composer
This will give you the path to composer like "/usr/bin/composer"
Then use that path in the command below to overcome the memory limit using the php flag for no memory limit, like this:
php -d memory_limit=-1 /usr/bin/composer update
Composer require runs out of memory. PHP Fatal error: Allowed memory size of 1610612736 bytes exhausted
To get the current memory_limit value, run:
php -r "echo ini_get('memory_limit').PHP_EOL;"
Try increasing the limit in your php.ini
file (ex. /etc/php5/cli/php.ini
for Debian-like systems):
; Use -1 for unlimited or define an explicit value like 2G
memory_limit = -1
Or, you can increase the limit with a command-line argument:
php -d memory_limit=-1 composer.phar require hwi/oauth-bundle php-http/guzzle6-adapter php-http/httplug-bundle
To get loaded php.ini files location try:
php --ini
Another quick solution:
php composer.phar COMPOSER_MEMORY_LIMIT=-1 require hwi/oauth-bundle php-http/guzzle6-adapter php-http/httplug-bundle
Or just:
COMPOSER_MEMORY_LIMIT=-1 composer require hwi/oauth-bundle php-http/guzzle6-adapter php-http/httplug-bundle
Related Topics
How to Re-Index the Values of an Array in PHP
Laravel 5 Failed Opening Required Bootstrap/../Vendor/Autoload.PHP
Remove Warning Messages in PHP
How to Get First 5 Characters from String
Redirecting to Previous Page After Login - PHP
Why Is Pdo Better For Escaping MySQL Queries/Querystrings Than MySQL_Real_Escape_String
Mongodb Duplicate Documents Even After Adding Unique Key
Compare Multiple Values in PHP
How to Run a PHP Script Inside a HTML File
Fatal Error: Call to a Member Function Prepare() on Null
How to Replace Text Urls and Exclude Urls in HTML Tags
PHP Expression ≪≪≪Eob
Insert - Number of Bind Variables Doesn't Match Number of Fields in Prepared Statement