From 7e573530c378a6b34c249bb92078c46bd4eb6cee Mon Sep 17 00:00:00 2001 From: Matthieu Napoli Date: Sat, 26 Sep 2026 23:39:15 +0200 Subject: [PATCH 1/2] Write the PHP-FPM timeout message on a single line Lambda turns each line written to stdout into a separate log event: the message was split into 3 events with the same timestamp, and only the first one started with the request ID. Searching the logs of a request missed the two explanatory lines, and log viewers could show them out of order. Also fix the link, the `#accessing-the-internet` anchor no longer exists. Claude-Session: https://claude.ai/code/session_01Awk33iZ9mDSg1xgSAPkgGK --- src/FpmRuntime/FpmHandler.php | 5 ++++- tests/FpmRuntime/FpmHandlerTest.php | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/FpmRuntime/FpmHandler.php b/src/FpmRuntime/FpmHandler.php index c1b0049fd..5699fcfeb 100644 --- a/src/FpmRuntime/FpmHandler.php +++ b/src/FpmRuntime/FpmHandler.php @@ -148,7 +148,10 @@ 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"; + // A single line: Lambda turns each line into a separate log event, and only this one starts with the request ID + 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. diff --git a/tests/FpmRuntime/FpmHandlerTest.php b/tests/FpmRuntime/FpmHandlerTest.php index 840e8ba0a..f3e143f7e 100644 --- a/tests/FpmRuntime/FpmHandlerTest.php +++ b/tests/FpmRuntime/FpmHandlerTest.php @@ -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', From 20ce33d546a63ffcaff76c59dd9615adee0e1878 Mon Sep 17 00:00:00 2001 From: Matthieu Napoli Date: Sun, 27 Sep 2026 10:33:43 +0200 Subject: [PATCH 2/2] Remove comment --- src/FpmRuntime/FpmHandler.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/FpmRuntime/FpmHandler.php b/src/FpmRuntime/FpmHandler.php index 5699fcfeb..8c1befdf3 100644 --- a/src/FpmRuntime/FpmHandler.php +++ b/src/FpmRuntime/FpmHandler.php @@ -148,7 +148,6 @@ public function handleRequest(HttpRequestEvent $event, Context $context): HttpRe $response = $this->client->readResponse($socketId, $timeoutDelayInMs); } catch (TimedoutException) { $invocationId = $context->getAwsRequestId(); - // A single line: Lambda turns each line into a separate log event, and only this one starts with the request ID 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";