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
4 changes: 3 additions & 1 deletion src/FpmRuntime/FpmHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,9 @@ public function handleRequest(HttpRequestEvent $event, Context $context): HttpRe
$response = $this->client->readResponse($socketId, $timeoutDelayInMs);
} catch (TimedoutException) {
$invocationId = $context->getAwsRequestId();
echo "$invocationId The PHP script timed out. Bref will now restart PHP-FPM to start from a clean slate and flush the PHP logs.\nTimeouts can happen for example when trying to connect to a remote API or database, if this happens continuously check for those.\nIf you are using a RDS database, read this: https://bref.sh/docs/environment/database.html#accessing-the-internet\n";
echo "$invocationId The PHP script timed out. Bref will now restart PHP-FPM to start from a clean slate and flush the PHP logs. "
. 'Timeouts can happen for example when trying to connect to a remote API or database, if this happens continuously check for those. '
. "If you are using a RDS database, read this: https://bref.sh/docs/environment/database#vpc-databases-private-network\n";

/**
* Restart FPM so that the blocked script is 100% terminated and that its logs are flushed to stderr.
Expand Down
3 changes: 3 additions & 0 deletions tests/FpmRuntime/FpmHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1221,6 +1221,9 @@ public function test FPM timeouts are recovered from()
], $this->fakeContext);
$this->fail('No exception was thrown');
} catch (Timeout $e) {
// A single line starting with the request ID: Lambda turns each line into a separate log event
self::assertMatchesRegularExpression('/^abc The PHP script timed out\. [^\n]+\n$/', ob_get_contents());

// PHP-FPM should work after that
$statusCode = $this->fpm->handle([
'version' => '1.0',
Expand Down
Loading