Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve the way time_limit and memory_limit is being set #2863

Merged
merged 2 commits into from
Oct 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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