Skip to content

Commit 05c0858

Browse files
authored
Merge pull request #787 from laravel/feat/franken-request-timeout
[2.x] Uses Octane's max execution time
2 parents 08e08ec + e71babf commit 05c0858

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

bin/frankenphp-worker.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@
3434
$worker = null;
3535
$requestCount = 0;
3636
$maxRequests = $_ENV['MAX_REQUESTS'] ?? $_SERVER['MAX_REQUESTS'];
37+
$requestMaxExecutionTime = $_ENV['REQUEST_MAX_EXECUTION_TIME'] ?? $_SERVER['REQUEST_MAX_EXECUTION_TIME'] ?? null;
38+
39+
if (PHP_OS_FAMILY === 'Linux' && ! is_null($requestMaxExecutionTime)) {
40+
set_time_limit((int) $requestMaxExecutionTime);
41+
}
3742

3843
try {
3944
$handleRequest = static function () use (&$worker, $basePath, $frankenPhpClient) {

src/Commands/StartFrankenPhpCommand.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ public function handle(ServerProcessInspector $inspector, ServerStateFile $serve
8888
'APP_PUBLIC_PATH' => public_path(),
8989
'LARAVEL_OCTANE' => 1,
9090
'MAX_REQUESTS' => $this->option('max-requests'),
91+
'REQUEST_MAX_EXECUTION_TIME' => $this->maxExecutionTime(),
9192
'CADDY_SERVER_ADMIN_PORT' => $this->adminPort(),
9293
'CADDY_SERVER_LOG_LEVEL' => $this->option('log-level') ?: (app()->environment('local') ? 'INFO' : 'WARN'),
9394
'CADDY_SERVER_LOGGER' => 'json',
@@ -179,6 +180,16 @@ protected function buildMercureConfig()
179180
return "$config\n\t\t}";
180181
}
181182

183+
/**
184+
* Get the maximum number of seconds that workers should be allowed to execute a single request.
185+
*
186+
* @return int
187+
*/
188+
protected function maxExecutionTime()
189+
{
190+
return config('octane.max_execution_time', 30);
191+
}
192+
182193
/**
183194
* Write the FrankenPHP server state file.
184195
*
@@ -282,6 +293,11 @@ protected function writeServerOutput($server)
282293
}
283294

284295
if ($debug['level'] !== 'info') {
296+
// Request timeout...
297+
if (isset($debug['exit_status']) && $debug['exit_status'] === 255) {
298+
return;
299+
}
300+
285301
return $this->error($debug['msg']);
286302
}
287303
});

0 commit comments

Comments
 (0)