From 47156103a611954965f5858cfc84e4ee6b1ef6f4 Mon Sep 17 00:00:00 2001 From: Kirill chEbba Chebunin Date: Fri, 24 Aug 2012 13:53:02 +0400 Subject: [PATCH 1/6] Remove hard coded memory limit. Add troubleshooting doc --- bin/composer | 1 - doc/articles/troubleshooting.md | 25 +++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 doc/articles/troubleshooting.md diff --git a/bin/composer b/bin/composer index 1ea4284e7..f65da48d8 100755 --- a/bin/composer +++ b/bin/composer @@ -7,7 +7,6 @@ use Composer\Console\Application; error_reporting(-1); @ini_set('display_errors', 1); -@ini_set('memory_limit', '512M'); // run the command application $application = new Application(); diff --git a/doc/articles/troubleshooting.md b/doc/articles/troubleshooting.md new file mode 100644 index 000000000..36cc54f14 --- /dev/null +++ b/doc/articles/troubleshooting.md @@ -0,0 +1,25 @@ + +# Memory limit errors + +If composer shows memory errors on some commands: + + PHP Fatal error: Allowed memory size of XXXXXX bytes exhausted <...> + +The `memory_limit` ini value should be increased. + +Get current value: + + php -r "echo ini_get('memory_limit').PHP_EOL;" + + +Increase limit with `php.ini` for a `CLI SAPI` (ex. `/etc/php5/cli/php.ini` for Debian-like systems): + + ; Use -1 for unlimited or define expicit value like 512M + memory_limit = -1 + +Or with comand line arguments: + + php -d memory_limit=-1 composer.phar <...> + From 99f3444f3062ad0b2da94b4a82cdb57025691823 Mon Sep 17 00:00:00 2001 From: Kirill chEbba Chebunin Date: Fri, 24 Aug 2012 14:35:16 +0400 Subject: [PATCH 2/6] Fix typo in troubleshooting article --- doc/articles/troubleshooting.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/articles/troubleshooting.md b/doc/articles/troubleshooting.md index 36cc54f14..9e3cb06a2 100644 --- a/doc/articles/troubleshooting.md +++ b/doc/articles/troubleshooting.md @@ -16,10 +16,10 @@ Get current value: Increase limit with `php.ini` for a `CLI SAPI` (ex. `/etc/php5/cli/php.ini` for Debian-like systems): - ; Use -1 for unlimited or define expicit value like 512M + ; Use -1 for unlimited or define explicit value like 512M memory_limit = -1 -Or with comand line arguments: +Or with command line arguments: php -d memory_limit=-1 composer.phar <...> From 4f129424e1915d6a4274ed17b40a30b6070627a9 Mon Sep 17 00:00:00 2001 From: Kirill chEbba Chebunin Date: Fri, 24 Aug 2012 17:06:03 +0400 Subject: [PATCH 3/6] Increase memory_limit to 256M if it is lower than this value --- bin/composer | 25 +++++++++++++++++++++++++ doc/articles/troubleshooting.md | 3 +++ 2 files changed, 28 insertions(+) diff --git a/bin/composer b/bin/composer index f65da48d8..7a0f8dbf5 100755 --- a/bin/composer +++ b/bin/composer @@ -8,6 +8,31 @@ use Composer\Console\Application; error_reporting(-1); @ini_set('display_errors', 1); +$memoryInBytes = function ($value) { + //$memoryLimit = ini_get('memory_limit'); + + $unit = strtolower(substr($value, -1, 1)); + $value = (int) $value; + switch($unit) { + case 'g': + $value *= 1024; + case 'm': + $value *= 1024; + case 'k': + $value *= 1024; + } + + return $value; +}; + +$memoryLimit = trim(ini_get('memory_limit')); +// Increase memory_limit if it is lower than 256M +if ($memoryLimit != -1 && $memoryInBytes($memoryLimit) < 256 * 1024 * 1024) { + @ini_set('memory_limit', '256M'); + printf('Warning: memory_limit was increased from %s to %s' . PHP_EOL . PHP_EOL, $memoryLimit, '256M'); +} +unset($memoryInBytes); + // run the command application $application = new Application(); $application->run(); diff --git a/doc/articles/troubleshooting.md b/doc/articles/troubleshooting.md index 9e3cb06a2..ecf4d239b 100644 --- a/doc/articles/troubleshooting.md +++ b/doc/articles/troubleshooting.md @@ -9,6 +9,9 @@ If composer shows memory errors on some commands: The `memory_limit` ini value should be increased. +> **Note:** Composer internaly increases the memory_limit to 256M. +> It is a good idea to create an issue for composer if you get memory errors. + Get current value: php -r "echo ini_get('memory_limit').PHP_EOL;" From ba45ef2b7092b76029c8663946f160c4759d7a55 Mon Sep 17 00:00:00 2001 From: Kirill chEbba Chebunin Date: Fri, 24 Aug 2012 17:25:10 +0400 Subject: [PATCH 4/6] Remove commented code forom cli script --- bin/composer | 2 -- 1 file changed, 2 deletions(-) diff --git a/bin/composer b/bin/composer index 7a0f8dbf5..5e2500e36 100755 --- a/bin/composer +++ b/bin/composer @@ -9,8 +9,6 @@ error_reporting(-1); @ini_set('display_errors', 1); $memoryInBytes = function ($value) { - //$memoryLimit = ini_get('memory_limit'); - $unit = strtolower(substr($value, -1, 1)); $value = (int) $value; switch($unit) { From 21596b2ccd2e3d434f0088f176c1a58613df990d Mon Sep 17 00:00:00 2001 From: Kirill chEbba Chebunin Date: Fri, 24 Aug 2012 17:49:35 +0400 Subject: [PATCH 5/6] Increase memory to 512M, remove warning --- bin/composer | 7 +++---- doc/articles/troubleshooting.md | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/bin/composer b/bin/composer index 5e2500e36..b22be4059 100755 --- a/bin/composer +++ b/bin/composer @@ -24,10 +24,9 @@ $memoryInBytes = function ($value) { }; $memoryLimit = trim(ini_get('memory_limit')); -// Increase memory_limit if it is lower than 256M -if ($memoryLimit != -1 && $memoryInBytes($memoryLimit) < 256 * 1024 * 1024) { - @ini_set('memory_limit', '256M'); - printf('Warning: memory_limit was increased from %s to %s' . PHP_EOL . PHP_EOL, $memoryLimit, '256M'); +// Increase memory_limit if it is lower than 512M +if ($memoryLimit != -1 && $memoryInBytes($memoryLimit) < 512 * 1024 * 1024) { + @ini_set('memory_limit', '512M'); } unset($memoryInBytes); diff --git a/doc/articles/troubleshooting.md b/doc/articles/troubleshooting.md index ecf4d239b..cbb2ab519 100644 --- a/doc/articles/troubleshooting.md +++ b/doc/articles/troubleshooting.md @@ -9,7 +9,7 @@ If composer shows memory errors on some commands: The `memory_limit` ini value should be increased. -> **Note:** Composer internaly increases the memory_limit to 256M. +> **Note:** Composer internaly increases the memory_limit to 512M. > It is a good idea to create an issue for composer if you get memory errors. Get current value: From 34c4f94619e9389225e7add459173ef45304b154 Mon Sep 17 00:00:00 2001 From: Kirill chEbba Chebunin Date: Fri, 24 Aug 2012 18:32:36 +0400 Subject: [PATCH 6/6] Fix typo in troubleshooting doc --- doc/articles/troubleshooting.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/articles/troubleshooting.md b/doc/articles/troubleshooting.md index cbb2ab519..3245b3b2a 100644 --- a/doc/articles/troubleshooting.md +++ b/doc/articles/troubleshooting.md @@ -9,7 +9,7 @@ If composer shows memory errors on some commands: The `memory_limit` ini value should be increased. -> **Note:** Composer internaly increases the memory_limit to 512M. +> **Note:** Composer internally increases the memory_limit to 512M. > It is a good idea to create an issue for composer if you get memory errors. Get current value: