Skip to content
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
15 changes: 15 additions & 0 deletions src/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ public function getConfig(): Config

protected function bootstrapCloud(ConsoleApplication|WebApplication $app): void
{
ini_set(
'max_execution_time',
(string) $this->getMaxExecutionSeconds(),
);

// Set Craft memory limit to just below PHP's limit
$this->setMemoryLimit(
ini_get('memory_limit'),
Expand Down Expand Up @@ -221,4 +226,14 @@ private function setMemoryLimit(int|string $limit, int|string $offset = 0): int|

return $memoryLimit;
}

private function getMaxExecutionSeconds(): int
{
if (Craft::$app->getRequest()->getIsWebRequest()) {
return 60;
}

// Include a buffer so PHP's limit is always hit before Lambda's
return 900 - 3;
}
}
6 changes: 0 additions & 6 deletions src/runtime/event/EventHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
class EventHandler implements Handler
{
private FpmHandler $fpmHandler;
private const MAX_SECONDS = 900 - 3;
private const MAX_HTTP_SECONDS = 60;

public function __construct(FpmHandler $fpmHandler)
{
Expand All @@ -19,8 +17,6 @@ public function __construct(FpmHandler $fpmHandler)

public function handle(mixed $event, Context $context)
{
ini_set('max_execution_time', self::MAX_SECONDS);

// is this a sqs event?
if (isset($event['Records'])) {
return (new SqsHandler())->handle($event, $context);
Expand All @@ -31,8 +27,6 @@ public function handle(mixed $event, Context $context)
return (new CliHandler())->handle($event, $context);
}

ini_set('max_execution_time', self::MAX_HTTP_SECONDS);

return $this->fpmHandler->handle($event, $context);
}
}
Loading