Skip to content

Commit f1e5ffd

Browse files
Only change max execution time if it's not already infinite or more.
1 parent 6422a45 commit f1e5ffd

File tree

5 files changed

+13
-5
lines changed

5 files changed

+13
-5
lines changed

webapp/src/Controller/Jury/ProblemController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ public function sampleZipAction(int $probId): StreamedResponse
262262
public function exportAction(int $problemId): StreamedResponse
263263
{
264264
// This might take a while.
265-
ini_set('max_execution_time', '300');
265+
Utils::extendMaxExecutionTime(300);
266266
/** @var Problem $problem */
267267
$problem = $this->em->createQueryBuilder()
268268
->from(Problem::class, 'p')

webapp/src/Service/ImportProblemService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function importZippedProblem(
6262
?array &$messages = []
6363
): ?Problem {
6464
// This might take a while.
65-
ini_set('max_execution_time', '300');
65+
Utils::extendMaxExecutionTime(300);
6666

6767
foreach (['info', 'warning', 'danger'] as $type) {
6868
$messages[$type] = [];

webapp/src/Service/RejudgingService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ public function createRejudging(
193193
public function finishRejudging(Rejudging $rejudging, string $action, ?callable $progressReporter = null): bool
194194
{
195195
// This might take a while.
196-
ini_set('max_execution_time', '300');
196+
Utils::extendMaxExecutionTime(300);
197197

198198
if ($rejudging->getEndtime()) {
199199
$error = sprintf('Error: rejudging already %s.', $rejudging->getValid() ? 'applied' : 'canceled');

webapp/src/Service/ScoreboardService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ public static function getICPCScoreKey(int $numSolved, int $totalTime, int $time
604604
*/
605605
public function refreshCache(Contest $contest, ?callable $progressReporter = null): void
606606
{
607-
ini_set('max_execution_time', 300);
607+
Utils::extendMaxExecutionTime(300);
608608

609609
$this->dj->auditlog('contest', $contest->getCid(), 'refresh scoreboard cache');
610610

webapp/src/Utils/Utils.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,7 @@ public static function sanitizeSvg(string $svgContents): string | false
737737
$sanitizer = new SvgSanitizer();
738738
$sanitizer->removeRemoteReferences(true);
739739
$sanitizer->minify(true);
740-
740+
741741
return $sanitizer->sanitize($svgContents);
742742
}
743743

@@ -1008,4 +1008,12 @@ public static function parseMetadata(string $raw_metadata): array
10081008

10091009
return $res;
10101010
}
1011+
1012+
public static function extendMaxExecutionTime(int $minimumMaxExecutionTime): void
1013+
{
1014+
$maxExecutionTime = (int)ini_get('max_execution_time');
1015+
if ($maxExecutionTime !== 0 && $maxExecutionTime < $minimumMaxExecutionTime) {
1016+
ini_set('max_execution_time', $minimumMaxExecutionTime);
1017+
}
1018+
}
10111019
}

0 commit comments

Comments
 (0)