Skip to content

Commit

Permalink
Merge pull request #787 from laravel/feat/franken-request-timeout
Browse files Browse the repository at this point in the history
[2.x] Uses Octane's max execution time
  • Loading branch information
nunomaduro authored Dec 21, 2023
2 parents 08e08ec + e71babf commit 05c0858
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
5 changes: 5 additions & 0 deletions bin/frankenphp-worker.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 (PHP_OS_FAMILY === 'Linux' && ! is_null($requestMaxExecutionTime)) {
set_time_limit((int) $requestMaxExecutionTime);
}

try {
$handleRequest = static function () use (&$worker, $basePath, $frankenPhpClient) {
Expand Down
16 changes: 16 additions & 0 deletions src/Commands/StartFrankenPhpCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -282,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']);
}
});
Expand Down

0 comments on commit 05c0858

Please sign in to comment.