Skip to content

Commit

Permalink
Merge pull request #2863 from bolt/set_memory_limit_better
Browse files Browse the repository at this point in the history
Improve the way `time_limit` and `memory_limit` is being set
  • Loading branch information
bobdenotter authored Oct 15, 2021
2 parents b35790c + 5e68faa commit 69489c5
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
1 change: 1 addition & 0 deletions bin/composer-script/Script.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public static function run(string $command): int
// We'll have to attempt one, and otherwise fall back to the other.

try {
/* @phpstan-ignore-next-line */
$process = new Process($command);
} catch (\TypeError $e) {
$process = new Process([$command]);
Expand Down
10 changes: 7 additions & 3 deletions bin/console
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,20 @@ use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Dotenv\Dotenv;
use Symfony\Component\ErrorHandler\Debug;
use Bolt\Configuration\Config;

if (!in_array(PHP_SAPI, ['cli', 'phpdbg', 'embed'], true)) {
echo 'Warning: The console should be invoked via the CLI version of PHP, not the '.PHP_SAPI.' SAPI'.PHP_EOL;
}

set_time_limit(0);
@ini_set('memory_limit', '1024M');

require dirname(__DIR__).'/vendor/autoload.php';

// Set the `time_limit` and `memory_limit`, if we're allowed to
set_time_limit(0);
if (Config::convertPHPSizeToBytes(ini_get('memory_limit')) < 1073741824) {
@ini_set('memory_limit', '1024M');
}

if (!class_exists(Application::class) || !class_exists(Dotenv::class)) {
throw new LogicException('You need to add "symfony/framework-bundle" and "symfony/dotenv" as Composer dependencies.');
}
Expand Down
12 changes: 9 additions & 3 deletions public/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,21 @@

declare(strict_types=1);

use Bolt\Configuration\Config;
use Bolt\Kernel;

use Symfony\Component\Dotenv\Dotenv;
use Symfony\Component\ErrorHandler\Debug;
use Symfony\Component\HttpFoundation\Request;

require dirname(__DIR__).'/vendor/autoload.php';
require dirname(__DIR__) . '/vendor/autoload.php';

// Set the `time_limit` and `memory_limit`, if we're allowed to
set_time_limit(0);
if (Config::convertPHPSizeToBytes(ini_get('memory_limit')) < 1073741824) {
@ini_set('memory_limit', '1024M');
}

(new Dotenv())->bootEnv(dirname(__DIR__).'/.env');
(new Dotenv())->bootEnv(dirname(__DIR__) . '/.env');

if ($_SERVER['APP_DEBUG']) {
umask(0000);
Expand Down
2 changes: 1 addition & 1 deletion src/Configuration/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ public function getMaxUploadDescription(): string
/**
* This function transforms the php.ini notation for numbers (like '2M') to an integer (2*1024*1024 in this case)
*/
private function convertPHPSizeToBytes(string $size): int
public static function convertPHPSizeToBytes(string $size): int
{
$suffix = mb_strtoupper(mb_substr($size, -1));
if (! in_array($suffix, ['P', 'T', 'G', 'M', 'K'], true)) {
Expand Down

0 comments on commit 69489c5

Please sign in to comment.