Asked  7 Months ago    Answers:  5   Viewed   40 times

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

 Answers

71

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
Wednesday, March 31, 2021
 
Drazisil
answered 7 Months ago
21

You need to increase your script memory by using this:

ini_set('memory_limit', '-1'); 

You need to use this line at the top of file.

By increasing memory_limit your script will take unlimited memory usage of server.

If you have access on php.ini file than you can increase limit from php.ini file otherwise you need to add this line.

Side note:

If you think unlimited memory will be effected on other areas than you can set custom value as:

ini_set('memory_limit', '512M');  //increase size as you need
Saturday, May 29, 2021
 
jenny
answered 5 Months ago
41

Why not use a library that is more memory optimized, simple HTML DOM is just not necessary any longer:

$html = new DOMDocument;
$html->loadHTMLFile('http://www.oddsshark.com/mlb/odds');
echo $html->saveHTML();

More suggestions are available with the reference question about that topic:

  • How do you parse and process HTML/XML in PHP?
Saturday, May 29, 2021
 
TMichel
answered 5 Months ago
33

I've solved this in the past by using simply:

php -d memory_limit=1G /usr/local/bin/composer update --prefer-dist --no-dev

Where the no-dev may help reduce the memory footprint too - certainly speed.

Saturday, May 29, 2021
 
DilbertDave
answered 5 Months ago
62

The solution is found. For some reason my composer.json contained "ext-http": "*".

"require": {
    "ext-http": "*"
}

Removing this line fixed the problem. I don't know why it contained "ext-http": "*" and I don't fully understand why removing it would fix the problem. (Is it because it is looking for the extension, but can not find it?)

(Thank you to everyone trying to help me fix the problem!)

Update: It might be worth looking at the other answers too. I'm no longer using PHP so I can't check the correctness of these new answers.

Sunday, July 4, 2021
 
EnTee
answered 4 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :
 
Share