Laravel: 503 service unavailable on shared hosting [duplicate] - php

I am trying to add HWIOAuthBundle to my project by running the below command.
composer require hwi/oauth-bundle php-http/guzzle6-adapter php-http/httplug-bundle
HWIOAuthBundle github: https://github.com/hwi/HWIOAuthBundle
When I try to run composer require I am getting the out of memory error.
Using version ^0.6.0#dev for hwi/oauth-bundle Using version ^1.2#dev
for php-http/guzzle6-adapter Using version ^1.10#dev for
php-http/httplug-bundle ./composer.json has been updated Loading
composer repositories with package information Updating dependencies
(including require-dev)
PHP Fatal error: Allowed memory size of 1610612736 bytes exhausted
(tried to allocate 67108864 bytes) in
phar:///usr/local/Cellar/composer/1.4.2/libexec/composer.phar/src/Composer/DependencyResolver/Solver.php on line 220
Fatal error: Allowed memory size of 1610612736 bytes exhausted (tried
to allocate 67108864 bytes) in
phar:///usr/local/Cellar/composer/1.4.2/libexec/composer.phar/src/Composer/DependencyResolver/Solver.php on line 220
I tried setting the memory_limit to 2G in my php.ini file but did not work. I found my php.ini by running php -i | grep php.ini

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

In my case I was trying to require this package when I got this error.
You can run like this, and you don't have to update the PHP INI file:
COMPOSER_MEMORY_LIMIT=-1 composer require huddledigital/zendesk-laravel

Another solution from the manual:
Composer also respects a memory limit defined by the COMPOSER_MEMORY_LIMIT environment variable:
COMPOSER_MEMORY_LIMIT=-1 composer.phar <...>
Or in my case
export COMPOSER_MEMORY_LIMIT=-1
composer <...>

Same problem, none of anything related to "memory_limit" worked, but..
composer self-update --2
..solved my problem. (upgrade: 1.10.17 -> 2.0.4)

On Windows 10;
Goto C:\ProgramData\ComposerSetup\bin
Edit: composer.bat and add memory_limit=-1 in the last line as shown below.
#echo OFF
:: in case DelayedExpansion is on and a path contains !
setlocal DISABLEDELAYEDEXPANSION
php -d memory_limit=-1 "%~dp0composer.phar" %*
Problem solved ;)

Since none of the previous answers included set it took me a bit to figure out how to do it in Windows without altering the php.ini, but here's what worked for me:
set COMPOSER_MEMORY_LIMIT=-1
composer require hwi/oauth-bundle php-http/guzzle6-adapter php-http/httplug-bundle

I have bypassed the problem in a Homestead Laravel (vagrant) virtual machine running the composer commands preceded by COMPOSER_MEMORY_LIMIT=-1:
Examples
To update Composer:
COMPOSER_MEMORY_LIMIT=-1 composer update
To install a package:
COMPOSER_MEMORY_LIMIT=-1 composer require spatie/laravel-translatable

For this error in macOS Catalina and macOS Big Sur use this line:
php -d memory_limit=-1 /usr/local/bin/composer update --no-plugins
I used this line to update on Symfony 5. This command also worked with laravel 7.

Just set the memory_limit specifying the full route of your composer.phar file and update, in my case with the command:
php -d memory_limit=-1 C:/wamp64/composer.phar update

Sometimes the problem is in the composer memory limit. In my case, I tried increasing the php memory limit but still got the error.
You can use COMPOSER_MEMORY_LIMIT=-1 to get around that.
Use it as a prefix:
COMPOSER_MEMORY_LIMIT=-1 composer require the/library
You have to prefix it again in the future.
Hope this helps.

It was recently identified that Composer consumes high CPU + memory on packages that have a lot of historical tags. See composer/composer#7577
A workaround to this problem is using symfony/flex or https://github.com/rubenrua/symfony-clean-tags-composer-plugin
composer global require rubenrua/symfony-clean-tags-composer-plugin

Just in case you get a composer error with:
Could not open input file: composer
run:
php -d memory_limit=-1 /usr/local/bin/composer require ...

For skipping memory limit and version error use the code below:
COMPOSER_MEMORY_LIMIT=-1 composer require <package-name> --ignore-platform-reqs

what about windows?
i use windows 10 and this command worked for me,
php -d memory_limit=-1 "C:\ProgramData\ComposerSetup\bin\composer.phar" update

Composer 2.0 preview is available now: https://github.com/composer/composer/releases
Fixed issue for me. You can set up a preview with composer self-update --preview
EDIT: Composer 2 with memory tuning released

For me, this works on shared hosting.
COMPOSER_MEMORY_LIMIT=-1 composer update

You can use a specific php Version when running Composer
If, like me, for some reason, you are using PHP 32 bits even though your computer is 64 bits, this will always limit the amount of memory allocated to Composer. I solved my problem this way:
Install a 64 bits php version somewhere on your computer (let's say in C:/php64)
In composer (using cygwin in my case), run:
COMPOSER_MEMORY_LIMIT=-1 C:/php64/php.exe ../composer.phar update

in windows by xampp i just changed:
;memory_limit=512M
in php.ini to:
memory_limit =-1
then restart the Apache by xampp
this is the result:
; Maximum amount of memory a script may consume
; http://php.net/memory-limit
memory_limit =-1
;memory_limit=512M

On Mac php 7.4
run
php --ini
Configuration File (php.ini) Path: /usr/local/etc/php/7.4
Loaded Configuration File: /usr/local/etc/php/7.4/php.ini
Scan for additional .ini files in: /usr/local/etc/php/7.4/conf.d
Additional .ini files parsed: /usr/local/etc/php/7.4/conf.d/ext-opcache.ini,
/usr/local/etc/php/7.4/conf.d/php-memory-limits.ini
If Additional .ini files parsed:
memory_limit needs to be changed in
/usr/local/etc/php/7.4/conf.d/php-memory-limits.ini
As Jose Seie writes, set memory to
memory_limit = -1 or memory_limit = 1G

Just want to share my situation on this matter.
Problem context:
Running composer in a vagrant box.
Was getting this message after try to run composer require "laravel-doctrine/orm:~1.4.13":
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.
Have tried setting php.ini memory limit to -1. (still not working).
Solution:
Apparently my composer.json and composer.lock has some issues.
Ran $ composer validate, and the result was:
"The lock file is not up to date with the latest changes in composer.json, it is recommended that you run composer update."
So I ran $ composer update, and all dependencies are resolved. Imho, when the dependencies has some issues, maybe the tree building is out of sync, hence the out of memory issue.
Hope this helps anyone out there.

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 <---- note the path
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.
Open and search for the memory_limit you can set the memory_limit = -1 to give an unlimited amount of memory to PHP processes or you can set 512MB, 1G, 2G, 5G,....
$ nano /usr/local/etc/php/7.3/php.ini
locate and set:
$ memory_limit = -1 or memory_limit = 1G
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;"
NOTE:
After saving, the new memory will be working. You don't need to do anything else.
More info: https://support.acquia.com/hc/en-us/articles/360036102614-Overriding-memory-limits-during-local-development-with-Composer

for Centos 7 use :
COMPOSER_MEMORY_LIMIT=-1 composer require hwi/oauth-bundle php-http/guzzle6-adapter php-http/httplug-bundle

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.
set memory_limit to -1 works for me ;) (vim /etc/php/7.2/cli/php.ini)

For Macbook:
run command sudo nano ~/.bash_profile to edit bash_profile then add alias composer="COMPOSER_MEMORY_LIMIT=-1 composer" in that file, then save and exit.
Hope this will solve the problem; Happy coding!

I condensed or packaged up the useful and accepted answer here into reusable (zsh) aliases/functions, for quicker and easier-to-remember reuse:
# composer high-memory
composermem() {
php -r "echo ini_get('memory_limit').PHP_EOL;"
}
alias composerbig='COMPOSER_MEMORY_LIMIT=-1 composer $1'
(php composer.phar is already aliased to composer on the system).

I solved this problem using this command COMPOSER_MEMORY_LIMIT=-1
Example: COMPOSER_MEMORY_LIMIT=-1 composer requires larval/ui

the options on this page worked for me
https://www.jesusamieiro.com/php-fatal-error-allowed-memory-size-of-1610612736-bytes-exhausted/
To be more precise solution one:
COMPOSER_MEMORY_LIMIT=-1 composer update

Make sure to not require a package before making sure the vendor folder exists.
Check if you have done composer install before. You may be just cloned the repository to your machine. So, you have to install the old packages before requiring a new one. Or you may want to include this option --profile to your composer command to see the timing and memory usage information.

In my case:
Windows 10 and Docker Desktop works:
docker-compose -f .docker/docker-compose.yml exec php env COMPOSER_MEMORY_LIMIT=-1 composer require fideloper/proxy

You just need to increase memory limit on "php.ini" file to solve the problem
find the "memory_limit" in php.ini file.
just change memory_limit value to 2G like below
;http://php.net/memory-limit
memory_limit=2G
to relocate the php file by using below command.
php --ini

Related

Fatal error: Allowed memory size of 1610612736 bytes exhausted (tried to allocate 83886080 bytes) using composer on go daddy server [duplicate]

I am trying to add HWIOAuthBundle to my project by running the below command.
composer require hwi/oauth-bundle php-http/guzzle6-adapter php-http/httplug-bundle
HWIOAuthBundle github: https://github.com/hwi/HWIOAuthBundle
When I try to run composer require I am getting the out of memory error.
Using version ^0.6.0#dev for hwi/oauth-bundle Using version ^1.2#dev
for php-http/guzzle6-adapter Using version ^1.10#dev for
php-http/httplug-bundle ./composer.json has been updated Loading
composer repositories with package information Updating dependencies
(including require-dev)
PHP Fatal error: Allowed memory size of 1610612736 bytes exhausted
(tried to allocate 67108864 bytes) in
phar:///usr/local/Cellar/composer/1.4.2/libexec/composer.phar/src/Composer/DependencyResolver/Solver.php on line 220
Fatal error: Allowed memory size of 1610612736 bytes exhausted (tried
to allocate 67108864 bytes) in
phar:///usr/local/Cellar/composer/1.4.2/libexec/composer.phar/src/Composer/DependencyResolver/Solver.php on line 220
I tried setting the memory_limit to 2G in my php.ini file but did not work. I found my php.ini by running php -i | grep php.ini
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
In my case I was trying to require this package when I got this error.
You can run like this, and you don't have to update the PHP INI file:
COMPOSER_MEMORY_LIMIT=-1 composer require huddledigital/zendesk-laravel
Another solution from the manual:
Composer also respects a memory limit defined by the COMPOSER_MEMORY_LIMIT environment variable:
COMPOSER_MEMORY_LIMIT=-1 composer.phar <...>
Or in my case
export COMPOSER_MEMORY_LIMIT=-1
composer <...>
Same problem, none of anything related to "memory_limit" worked, but..
composer self-update --2
..solved my problem. (upgrade: 1.10.17 -> 2.0.4)
On Windows 10;
Goto C:\ProgramData\ComposerSetup\bin
Edit: composer.bat and add memory_limit=-1 in the last line as shown below.
#echo OFF
:: in case DelayedExpansion is on and a path contains !
setlocal DISABLEDELAYEDEXPANSION
php -d memory_limit=-1 "%~dp0composer.phar" %*
Problem solved ;)
Since none of the previous answers included set it took me a bit to figure out how to do it in Windows without altering the php.ini, but here's what worked for me:
set COMPOSER_MEMORY_LIMIT=-1
composer require hwi/oauth-bundle php-http/guzzle6-adapter php-http/httplug-bundle
I have bypassed the problem in a Homestead Laravel (vagrant) virtual machine running the composer commands preceded by COMPOSER_MEMORY_LIMIT=-1:
Examples
To update Composer:
COMPOSER_MEMORY_LIMIT=-1 composer update
To install a package:
COMPOSER_MEMORY_LIMIT=-1 composer require spatie/laravel-translatable
For this error in macOS Catalina and macOS Big Sur use this line:
php -d memory_limit=-1 /usr/local/bin/composer update --no-plugins
I used this line to update on Symfony 5. This command also worked with laravel 7.
Just set the memory_limit specifying the full route of your composer.phar file and update, in my case with the command:
php -d memory_limit=-1 C:/wamp64/composer.phar update
Sometimes the problem is in the composer memory limit. In my case, I tried increasing the php memory limit but still got the error.
You can use COMPOSER_MEMORY_LIMIT=-1 to get around that.
Use it as a prefix:
COMPOSER_MEMORY_LIMIT=-1 composer require the/library
You have to prefix it again in the future.
Hope this helps.
It was recently identified that Composer consumes high CPU + memory on packages that have a lot of historical tags. See composer/composer#7577
A workaround to this problem is using symfony/flex or https://github.com/rubenrua/symfony-clean-tags-composer-plugin
composer global require rubenrua/symfony-clean-tags-composer-plugin
Just in case you get a composer error with:
Could not open input file: composer
run:
php -d memory_limit=-1 /usr/local/bin/composer require ...
For skipping memory limit and version error use the code below:
COMPOSER_MEMORY_LIMIT=-1 composer require <package-name> --ignore-platform-reqs
what about windows?
i use windows 10 and this command worked for me,
php -d memory_limit=-1 "C:\ProgramData\ComposerSetup\bin\composer.phar" update
Composer 2.0 preview is available now: https://github.com/composer/composer/releases
Fixed issue for me. You can set up a preview with composer self-update --preview
EDIT: Composer 2 with memory tuning released
For me, this works on shared hosting.
COMPOSER_MEMORY_LIMIT=-1 composer update
You can use a specific php Version when running Composer
If, like me, for some reason, you are using PHP 32 bits even though your computer is 64 bits, this will always limit the amount of memory allocated to Composer. I solved my problem this way:
Install a 64 bits php version somewhere on your computer (let's say in C:/php64)
In composer (using cygwin in my case), run:
COMPOSER_MEMORY_LIMIT=-1 C:/php64/php.exe ../composer.phar update
in windows by xampp i just changed:
;memory_limit=512M
in php.ini to:
memory_limit =-1
then restart the Apache by xampp
this is the result:
; Maximum amount of memory a script may consume
; http://php.net/memory-limit
memory_limit =-1
;memory_limit=512M
On Mac php 7.4
run
php --ini
Configuration File (php.ini) Path: /usr/local/etc/php/7.4
Loaded Configuration File: /usr/local/etc/php/7.4/php.ini
Scan for additional .ini files in: /usr/local/etc/php/7.4/conf.d
Additional .ini files parsed: /usr/local/etc/php/7.4/conf.d/ext-opcache.ini,
/usr/local/etc/php/7.4/conf.d/php-memory-limits.ini
If Additional .ini files parsed:
memory_limit needs to be changed in
/usr/local/etc/php/7.4/conf.d/php-memory-limits.ini
As Jose Seie writes, set memory to
memory_limit = -1 or memory_limit = 1G
Just want to share my situation on this matter.
Problem context:
Running composer in a vagrant box.
Was getting this message after try to run composer require "laravel-doctrine/orm:~1.4.13":
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.
Have tried setting php.ini memory limit to -1. (still not working).
Solution:
Apparently my composer.json and composer.lock has some issues.
Ran $ composer validate, and the result was:
"The lock file is not up to date with the latest changes in composer.json, it is recommended that you run composer update."
So I ran $ composer update, and all dependencies are resolved. Imho, when the dependencies has some issues, maybe the tree building is out of sync, hence the out of memory issue.
Hope this helps anyone out there.
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 <---- note the path
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.
Open and search for the memory_limit you can set the memory_limit = -1 to give an unlimited amount of memory to PHP processes or you can set 512MB, 1G, 2G, 5G,....
$ nano /usr/local/etc/php/7.3/php.ini
locate and set:
$ memory_limit = -1 or memory_limit = 1G
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;"
NOTE:
After saving, the new memory will be working. You don't need to do anything else.
More info: https://support.acquia.com/hc/en-us/articles/360036102614-Overriding-memory-limits-during-local-development-with-Composer
for Centos 7 use :
COMPOSER_MEMORY_LIMIT=-1 composer require hwi/oauth-bundle php-http/guzzle6-adapter php-http/httplug-bundle
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.
set memory_limit to -1 works for me ;) (vim /etc/php/7.2/cli/php.ini)
For Macbook:
run command sudo nano ~/.bash_profile to edit bash_profile then add alias composer="COMPOSER_MEMORY_LIMIT=-1 composer" in that file, then save and exit.
Hope this will solve the problem; Happy coding!
I condensed or packaged up the useful and accepted answer here into reusable (zsh) aliases/functions, for quicker and easier-to-remember reuse:
# composer high-memory
composermem() {
php -r "echo ini_get('memory_limit').PHP_EOL;"
}
alias composerbig='COMPOSER_MEMORY_LIMIT=-1 composer $1'
(php composer.phar is already aliased to composer on the system).
I solved this problem using this command COMPOSER_MEMORY_LIMIT=-1
Example: COMPOSER_MEMORY_LIMIT=-1 composer requires larval/ui
the options on this page worked for me
https://www.jesusamieiro.com/php-fatal-error-allowed-memory-size-of-1610612736-bytes-exhausted/
To be more precise solution one:
COMPOSER_MEMORY_LIMIT=-1 composer update
Make sure to not require a package before making sure the vendor folder exists.
Check if you have done composer install before. You may be just cloned the repository to your machine. So, you have to install the old packages before requiring a new one. Or you may want to include this option --profile to your composer command to see the timing and memory usage information.
In my case:
Windows 10 and Docker Desktop works:
docker-compose -f .docker/docker-compose.yml exec php env COMPOSER_MEMORY_LIMIT=-1 composer require fideloper/proxy
You just need to increase memory limit on "php.ini" file to solve the problem
find the "memory_limit" in php.ini file.
just change memory_limit value to 2G like below
;http://php.net/memory-limit
memory_limit=2G
to relocate the php file by using below command.
php --ini

Fatal error: Allowed memory size of 1610612736 bytes exhausted but already allocated 1.75G

I keep getting this memory error
PHP Fatal error: Allowed memory size of 1610612736 bytes exhausted
(tried to allocate 67108864 bytes) in
phar:///usr/local/bin/composer/src/Composer/
DependencyResolver/Solver.php on line 220
I have tried everything. Increased the memory limit a few times already. I've redownloaded composer and composer.phar. I cloned my repo on a fresh install and the first composer install worked. For some reason every attempt after causes this error.
I even removed any differences in files from the master branch and my branch that could be causing this.
PhP version 7.1.25
Composer version 1.7.2
Code I edited in a config.yml file
create_course_space_whitelist_expression: '"staff" in affiliations or
"employee" in affiliations or "faculty" in affiliations or "guest" in
affiliations or "GR" in student_level'
old code:
create_course_space_whitelist_expression: '"staff" in affiliations or
"employee" in affiliations or "faculty" in affiliations or "guest" in
affiliations
Not sure where else to look. I updated two created files within Vendor but I'm deleting vendor before running composer install
EDIT:
I've been able to narrow down the cause. composer install works fine the when working with a clean version of the repo branch. However, when any change is made to the composer.json file, it fails
Running this command fixed it for me
php -d memory_limit=-1 /usr/local/bin/composer install
In my case with Xampp with Windows 10
i just changed:
;memory_limit=512M
by commenting this configuration, in php.ini to:
memory_limit =-1
then restart the Apache by xampp
Update Composer to version 2 and it will resolve this issue automatically.
composer self-update --2
Note : argument --2 is optional. it will upgrade the current composer version to 2 only. Without it, the composer will update to the latest version (it's the same version 2 currently but in future, it may be 3)
what about windows?
i use windows 10 and this command worked for me,
php -d memory_limit=-1 "C:\ProgramData\ComposerSetup\bin\composer.phar" update
Run COMPOSER_MEMORY_LIMIT=-1 composer install instead of composer install
in WINDOWS you can use this:
set COMPOSER_MEMORY_LIMIT=-1
in windows 10 and with terminal and laragon it worked for me
COMPOSER_MEMORY_LIMIT=-1 composer update
try this it's working for me

Unable to change Travis-CI PHP memory_limit

I’m having troubles in testing with php5.6 and composer: builds run out of memory (tried also with 2G limit instead of -1 but still fails).
I followed other examples and Travis' PHP guide to disable memory limit, but it’s apparently not having the desired result.
Lastly I’ve added the oneliner
echo "memory_limit=2G" >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
but composer install still fails after 1.5G.
Why is the limit not applied? According to composer docs changing the value in php.ini should be ok.
By more and more carefully reading the log (and better understanding TravisCI) I found out before_script is being run after dependency installation, so was not yet in effect when running composer.
I fixed by increasing the memory limit in before_install, by adding the following to .travis.yml:
before_install:
- echo "memory_limit=2G" >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
edit: as pointed out by #emix in the comments this is not the best way because this raises the memory for the full application, which could hide memory leaks.
The best way is to raise memory just for composer run, which can be accomplished by running composer this way:
COMPOSER_MEMORY_LIMIT=-1 travis_retry composer install --prefer-dist --no-interaction

Can not allocate memory error when install passport in laravel using composer

I am installing passport in laravel by composer using command
$ composer require laravel/passport
Using version ^6.0 for laravel/passport
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
mmap() failed: [12] Cannot allocate memory
mmap() failed: [12] Cannot allocate memory
Fatal error: Out of memory (allocated 483401728) (tried to allocate 8388608 bytes) in phar:///opt/cpanel/composer/bin/composer/src/Composer/DependencyResolver/Solver.php on line 220
I got above errors please help me if you have any solutions.
I was able to install Passport by temporarily removing PHP's memory limit. I found this idea here: https://laravel.io/forum/02-11-2014-composer-running-out-of-memory
$ php -d memory_limit=-1 /usr/local/bin/composer require laravel/passport --verbose --profile
I like this solution because it overrides the PHP limit only once, so it allows you to push forward without any lasting affects. This will allow you to wait and see if you continue to get issues later, such as in the production environment, etc.
The default PHP installation allocates 500 MB~ RAM I believe, and when I ran that above command, it consumed 712 MB of RAM.
Extra note
At that above URL, there is also mention of committing the composer.lock file in the production environment. Historically, it can be a concern if, for example, you are developing localmachine on MacOS or Windows and then your production environment is Linux. It might not be likely, but it is possible a person could experience issues due to arbitrary packages determining what dependencies to select based on the detected operating system. If you commit the lock file, you are caching the packages/versions. The performance benefits will stem from that, but caching breeds rigidity.
I'm not sure of the true likelihood of what I'm saying. I'm saying this about composer, but I've seen it with npm and JavaScript.
Try the following steps:
sudo fallocate -l 2G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
In the root of your project in the composer.json in the line of require "require": {"laravel/ui": "^1.1"} and next, composer update
Source
Memory limit errors.
Composer may sometimes fail on some commands with this message:
PHP Fatal error: Allowed memory size of XXXXXX bytes exhausted <...>
In this case, the PHP memory_limit should be increased.
Note: Composer internally increases the `memory_limit` to 1.5G.
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
Composer also respects a memory limit defined by the COMPOSER_MEMORY_LIMIT environment variable:
COMPOSER_MEMORY_LIMIT=-1 composer.phar <...>
Or, you can increase the limit with a command-line argument:
php -d memory_limit=-1 composer.phar <...>
This issue can also happen on cPanel instances, when the shell fork bomb protection is activated. For more information, see the documentation of the fork bomb feature on the cPanel site.
This answer might also be useful.

Composer require runs out of memory. PHP Fatal error: Allowed memory size of 1610612736 bytes exhausted

I am trying to add HWIOAuthBundle to my project by running the below command.
composer require hwi/oauth-bundle php-http/guzzle6-adapter php-http/httplug-bundle
HWIOAuthBundle github: https://github.com/hwi/HWIOAuthBundle
When I try to run composer require I am getting the out of memory error.
Using version ^0.6.0#dev for hwi/oauth-bundle Using version ^1.2#dev
for php-http/guzzle6-adapter Using version ^1.10#dev for
php-http/httplug-bundle ./composer.json has been updated Loading
composer repositories with package information Updating dependencies
(including require-dev)
PHP Fatal error: Allowed memory size of 1610612736 bytes exhausted
(tried to allocate 67108864 bytes) in
phar:///usr/local/Cellar/composer/1.4.2/libexec/composer.phar/src/Composer/DependencyResolver/Solver.php on line 220
Fatal error: Allowed memory size of 1610612736 bytes exhausted (tried
to allocate 67108864 bytes) in
phar:///usr/local/Cellar/composer/1.4.2/libexec/composer.phar/src/Composer/DependencyResolver/Solver.php on line 220
I tried setting the memory_limit to 2G in my php.ini file but did not work. I found my php.ini by running php -i | grep php.ini
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
In my case I was trying to require this package when I got this error.
You can run like this, and you don't have to update the PHP INI file:
COMPOSER_MEMORY_LIMIT=-1 composer require huddledigital/zendesk-laravel
Another solution from the manual:
Composer also respects a memory limit defined by the COMPOSER_MEMORY_LIMIT environment variable:
COMPOSER_MEMORY_LIMIT=-1 composer.phar <...>
Or in my case
export COMPOSER_MEMORY_LIMIT=-1
composer <...>
Same problem, none of anything related to "memory_limit" worked, but..
composer self-update --2
..solved my problem. (upgrade: 1.10.17 -> 2.0.4)
On Windows 10;
Goto C:\ProgramData\ComposerSetup\bin
Edit: composer.bat and add memory_limit=-1 in the last line as shown below.
#echo OFF
:: in case DelayedExpansion is on and a path contains !
setlocal DISABLEDELAYEDEXPANSION
php -d memory_limit=-1 "%~dp0composer.phar" %*
Problem solved ;)
Since none of the previous answers included set it took me a bit to figure out how to do it in Windows without altering the php.ini, but here's what worked for me:
set COMPOSER_MEMORY_LIMIT=-1
composer require hwi/oauth-bundle php-http/guzzle6-adapter php-http/httplug-bundle
I have bypassed the problem in a Homestead Laravel (vagrant) virtual machine running the composer commands preceded by COMPOSER_MEMORY_LIMIT=-1:
Examples
To update Composer:
COMPOSER_MEMORY_LIMIT=-1 composer update
To install a package:
COMPOSER_MEMORY_LIMIT=-1 composer require spatie/laravel-translatable
For this error in macOS Catalina and macOS Big Sur use this line:
php -d memory_limit=-1 /usr/local/bin/composer update --no-plugins
I used this line to update on Symfony 5. This command also worked with laravel 7.
Just set the memory_limit specifying the full route of your composer.phar file and update, in my case with the command:
php -d memory_limit=-1 C:/wamp64/composer.phar update
Sometimes the problem is in the composer memory limit. In my case, I tried increasing the php memory limit but still got the error.
You can use COMPOSER_MEMORY_LIMIT=-1 to get around that.
Use it as a prefix:
COMPOSER_MEMORY_LIMIT=-1 composer require the/library
You have to prefix it again in the future.
Hope this helps.
It was recently identified that Composer consumes high CPU + memory on packages that have a lot of historical tags. See composer/composer#7577
A workaround to this problem is using symfony/flex or https://github.com/rubenrua/symfony-clean-tags-composer-plugin
composer global require rubenrua/symfony-clean-tags-composer-plugin
Just in case you get a composer error with:
Could not open input file: composer
run:
php -d memory_limit=-1 /usr/local/bin/composer require ...
For skipping memory limit and version error use the code below:
COMPOSER_MEMORY_LIMIT=-1 composer require <package-name> --ignore-platform-reqs
what about windows?
i use windows 10 and this command worked for me,
php -d memory_limit=-1 "C:\ProgramData\ComposerSetup\bin\composer.phar" update
Composer 2.0 preview is available now: https://github.com/composer/composer/releases
Fixed issue for me. You can set up a preview with composer self-update --preview
EDIT: Composer 2 with memory tuning released
For me, this works on shared hosting.
COMPOSER_MEMORY_LIMIT=-1 composer update
You can use a specific php Version when running Composer
If, like me, for some reason, you are using PHP 32 bits even though your computer is 64 bits, this will always limit the amount of memory allocated to Composer. I solved my problem this way:
Install a 64 bits php version somewhere on your computer (let's say in C:/php64)
In composer (using cygwin in my case), run:
COMPOSER_MEMORY_LIMIT=-1 C:/php64/php.exe ../composer.phar update
in windows by xampp i just changed:
;memory_limit=512M
in php.ini to:
memory_limit =-1
then restart the Apache by xampp
this is the result:
; Maximum amount of memory a script may consume
; http://php.net/memory-limit
memory_limit =-1
;memory_limit=512M
On Mac php 7.4
run
php --ini
Configuration File (php.ini) Path: /usr/local/etc/php/7.4
Loaded Configuration File: /usr/local/etc/php/7.4/php.ini
Scan for additional .ini files in: /usr/local/etc/php/7.4/conf.d
Additional .ini files parsed: /usr/local/etc/php/7.4/conf.d/ext-opcache.ini,
/usr/local/etc/php/7.4/conf.d/php-memory-limits.ini
If Additional .ini files parsed:
memory_limit needs to be changed in
/usr/local/etc/php/7.4/conf.d/php-memory-limits.ini
As Jose Seie writes, set memory to
memory_limit = -1 or memory_limit = 1G
Just want to share my situation on this matter.
Problem context:
Running composer in a vagrant box.
Was getting this message after try to run composer require "laravel-doctrine/orm:~1.4.13":
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.
Have tried setting php.ini memory limit to -1. (still not working).
Solution:
Apparently my composer.json and composer.lock has some issues.
Ran $ composer validate, and the result was:
"The lock file is not up to date with the latest changes in composer.json, it is recommended that you run composer update."
So I ran $ composer update, and all dependencies are resolved. Imho, when the dependencies has some issues, maybe the tree building is out of sync, hence the out of memory issue.
Hope this helps anyone out there.
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 <---- note the path
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.
Open and search for the memory_limit you can set the memory_limit = -1 to give an unlimited amount of memory to PHP processes or you can set 512MB, 1G, 2G, 5G,....
$ nano /usr/local/etc/php/7.3/php.ini
locate and set:
$ memory_limit = -1 or memory_limit = 1G
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;"
NOTE:
After saving, the new memory will be working. You don't need to do anything else.
More info: https://support.acquia.com/hc/en-us/articles/360036102614-Overriding-memory-limits-during-local-development-with-Composer
for Centos 7 use :
COMPOSER_MEMORY_LIMIT=-1 composer require hwi/oauth-bundle php-http/guzzle6-adapter php-http/httplug-bundle
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.
set memory_limit to -1 works for me ;) (vim /etc/php/7.2/cli/php.ini)
For Macbook:
run command sudo nano ~/.bash_profile to edit bash_profile then add alias composer="COMPOSER_MEMORY_LIMIT=-1 composer" in that file, then save and exit.
Hope this will solve the problem; Happy coding!
I condensed or packaged up the useful and accepted answer here into reusable (zsh) aliases/functions, for quicker and easier-to-remember reuse:
# composer high-memory
composermem() {
php -r "echo ini_get('memory_limit').PHP_EOL;"
}
alias composerbig='COMPOSER_MEMORY_LIMIT=-1 composer $1'
(php composer.phar is already aliased to composer on the system).
I solved this problem using this command COMPOSER_MEMORY_LIMIT=-1
Example: COMPOSER_MEMORY_LIMIT=-1 composer requires larval/ui
the options on this page worked for me
https://www.jesusamieiro.com/php-fatal-error-allowed-memory-size-of-1610612736-bytes-exhausted/
To be more precise solution one:
COMPOSER_MEMORY_LIMIT=-1 composer update
Make sure to not require a package before making sure the vendor folder exists.
Check if you have done composer install before. You may be just cloned the repository to your machine. So, you have to install the old packages before requiring a new one. Or you may want to include this option --profile to your composer command to see the timing and memory usage information.
In my case:
Windows 10 and Docker Desktop works:
docker-compose -f .docker/docker-compose.yml exec php env COMPOSER_MEMORY_LIMIT=-1 composer require fideloper/proxy
You just need to increase memory limit on "php.ini" file to solve the problem
find the "memory_limit" in php.ini file.
just change memory_limit value to 2G like below
;http://php.net/memory-limit
memory_limit=2G
to relocate the php file by using below command.
php --ini

Categories