Skip to content

Commit

Permalink
set memory limit same as composer
Browse files Browse the repository at this point in the history
  • Loading branch information
freezy-sk authored and alcohol committed Oct 21, 2020
1 parent e89d68a commit 92bc3d1
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions bin/satis
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,39 @@ if ((!$loader = includeIfExists(__DIR__.'/../vendor/autoload.php')) && (!$loader
exit(1);
}

if (function_exists('ini_set')) {
// Set user defined memory limit or use Composer's user defined memory limit
if ($memoryLimit = getenv('SATIS_MEMORY_LIMIT')) {
@ini_set('memory_limit', $memoryLimit);
} elseif ($memoryLimit = getenv('COMPOSER_MEMORY_LIMIT')) {
@ini_set('memory_limit', $memoryLimit);
} else {
$memoryInBytes = function ($value) {
$unit = strtolower(substr($value, -1, 1));
$value = (int) $value;
switch($unit) {
case 'g':
$value *= 1024;
// no break (cumulative multiplier)
case 'm':
$value *= 1024;
// no break (cumulative multiplier)
case 'k':
$value *= 1024;
}

return $value;
};

$memoryLimit = trim(ini_get('memory_limit'));
// Increase memory_limit if it is lower than 1.5GB
if ($memoryLimit != -1 && $memoryInBytes($memoryLimit) < 1024 * 1024 * 1536) {
@ini_set('memory_limit', '1536M');
}
unset($memoryInBytes);
}
unset($memoryLimit);
}

$application = new Composer\Satis\Console\Application();
$application->run();

0 comments on commit 92bc3d1

Please sign in to comment.