From 56a818bca3a0754da9ada0029f3de13451367838 Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Thu, 21 Dec 2023 15:58:38 +0000 Subject: [PATCH 1/3] Uses Octane's max execution time --- bin/frankenphp-worker.php | 5 +++++ src/Commands/StartFrankenPhpCommand.php | 11 +++++++++++ 2 files changed, 16 insertions(+) diff --git a/bin/frankenphp-worker.php b/bin/frankenphp-worker.php index 1ffe6f0bb..b85aa0f6d 100644 --- a/bin/frankenphp-worker.php +++ b/bin/frankenphp-worker.php @@ -34,6 +34,11 @@ $worker = null; $requestCount = 0; $maxRequests = $_ENV['MAX_REQUESTS'] ?? $_SERVER['MAX_REQUESTS']; +$requestMaxExecutionTime = $_ENV['REQUEST_MAX_EXECUTION_TIME'] ?? $_SERVER['REQUEST_MAX_EXECUTION_TIME'] ?? null; + +if (! is_null($requestMaxExecutionTime)) { + set_time_limit((int) $requestMaxExecutionTime); +} try { $handleRequest = static function () use (&$worker, $basePath, $frankenPhpClient) { diff --git a/src/Commands/StartFrankenPhpCommand.php b/src/Commands/StartFrankenPhpCommand.php index 37bd0b257..cc6365c1d 100644 --- a/src/Commands/StartFrankenPhpCommand.php +++ b/src/Commands/StartFrankenPhpCommand.php @@ -88,6 +88,7 @@ public function handle(ServerProcessInspector $inspector, ServerStateFile $serve 'APP_PUBLIC_PATH' => public_path(), 'LARAVEL_OCTANE' => 1, 'MAX_REQUESTS' => $this->option('max-requests'), + 'REQUEST_MAX_EXECUTION_TIME' => $this->maxExecutionTime(), 'CADDY_SERVER_ADMIN_PORT' => $this->adminPort(), 'CADDY_SERVER_LOG_LEVEL' => $this->option('log-level') ?: (app()->environment('local') ? 'INFO' : 'WARN'), 'CADDY_SERVER_LOGGER' => 'json', @@ -179,6 +180,16 @@ protected function buildMercureConfig() return "$config\n\t\t}"; } + /** + * Get the maximum number of seconds that workers should be allowed to execute a single request. + * + * @return int + */ + protected function maxExecutionTime() + { + return config('octane.max_execution_time', 30); + } + /** * Write the FrankenPHP server state file. * From f8bc60dc287a35cde0709e124e3ec34f14ac71dc Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Thu, 21 Dec 2023 16:27:31 +0000 Subject: [PATCH 2/3] Only on Linux --- bin/frankenphp-worker.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/frankenphp-worker.php b/bin/frankenphp-worker.php index b85aa0f6d..b4292e981 100644 --- a/bin/frankenphp-worker.php +++ b/bin/frankenphp-worker.php @@ -36,7 +36,7 @@ $maxRequests = $_ENV['MAX_REQUESTS'] ?? $_SERVER['MAX_REQUESTS']; $requestMaxExecutionTime = $_ENV['REQUEST_MAX_EXECUTION_TIME'] ?? $_SERVER['REQUEST_MAX_EXECUTION_TIME'] ?? null; -if (! is_null($requestMaxExecutionTime)) { +if (PHP_OS_FAMILY === 'Linux' && ! is_null($requestMaxExecutionTime)) { set_time_limit((int) $requestMaxExecutionTime); } From e71babfc27b4c5e7c7feda65970401f7d030e578 Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Thu, 21 Dec 2023 16:44:04 +0000 Subject: [PATCH 3/3] Ignores timeouts on logs --- src/Commands/StartFrankenPhpCommand.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Commands/StartFrankenPhpCommand.php b/src/Commands/StartFrankenPhpCommand.php index cc6365c1d..398899287 100644 --- a/src/Commands/StartFrankenPhpCommand.php +++ b/src/Commands/StartFrankenPhpCommand.php @@ -293,6 +293,11 @@ protected function writeServerOutput($server) } if ($debug['level'] !== 'info') { + // Request timeout... + if (isset($debug['exit_status']) && $debug['exit_status'] === 255) { + return; + } + return $this->error($debug['msg']); } });