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
8 changes: 7 additions & 1 deletion runtime/layers/fpm/bootstrap
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,13 @@ if (! is_file($handlerFile)) {
$lambdaRuntime->failInitialization("Handler `$handlerFile` doesn't exist");
}

$phpFpm = new FpmHandler($handlerFile);
if (getenv('BREF_PHP_FPM_TIMEOUT')) {
$timeout = (int) getenv('BREF_PHP_FPM_TIMEOUT') * 1000;
} else {
$timeout = 30000;
}

$phpFpm = new FpmHandler($handlerFile, $timeout);
try {
$phpFpm->start();
} catch (\Throwable $e) {
Expand Down
7 changes: 5 additions & 2 deletions src/Event/Http/FpmHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,13 @@ final class FpmHandler extends HttpHandler
private $configFile;
/** @var Process|null */
private $fpm;
/** @var int */
private $socketReadWriteTimeout;

public function __construct(string $handler, string $configFile = self::CONFIG)
public function __construct(string $handler, int $socketReadWriteTimeout, string $configFile = self::CONFIG)
{
$this->handler = $handler;
$this->socketReadWriteTimeout = $socketReadWriteTimeout;
$this->configFile = $configFile;
}

Expand Down Expand Up @@ -78,7 +81,7 @@ public function start(): void
});

$this->client = new Client;
$this->connection = new UnixDomainSocket(self::SOCKET, 1000, 30000);
$this->connection = new UnixDomainSocket(self::SOCKET, 1000, $this->socketReadWriteTimeout);

$this->waitUntilReady();
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Handler/FpmHandlerLoadBalancerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ private function startFpm(string $handler): void
if ($this->fpm) {
$this->fpm->stop();
}
$this->fpm = new FpmHandler($handler, __DIR__ . '/PhpFpm/php-fpm.conf');
$this->fpm = new FpmHandler($handler, 5000, __DIR__ . '/PhpFpm/php-fpm.conf');
$this->fpm->start();
}
}
6 changes: 3 additions & 3 deletions tests/Handler/FpmHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1085,7 +1085,7 @@ public function test response with error_log()
*/
public function test FPM timeouts are recovered from()
{
$this->fpm = new FpmHandler(__DIR__ . '/PhpFpm/timeout.php', __DIR__ . '/PhpFpm/php-fpm.conf');
$this->fpm = new FpmHandler(__DIR__ . '/PhpFpm/timeout.php', 5000, __DIR__ . '/PhpFpm/php-fpm.conf');
$this->fpm->start();

try {
Expand Down Expand Up @@ -1124,7 +1124,7 @@ public function test warmer events do not invoke the application()
{
// Run `timeout.php` to make sure that the handler is not really executed.
// If it was, then PHP-FPM would timeout (and error).
$this->fpm = new FpmHandler(__DIR__ . '/PhpFpm/timeout.php', __DIR__ . '/PhpFpm/php-fpm.conf');
$this->fpm = new FpmHandler(__DIR__ . '/PhpFpm/timeout.php', 5000, __DIR__ . '/PhpFpm/php-fpm.conf');
$this->fpm->start();

$result = $this->fpm->handle([
Expand Down Expand Up @@ -1198,7 +1198,7 @@ private function startFpm(string $handler): void
if ($this->fpm) {
$this->fpm->stop();
}
$this->fpm = new FpmHandler($handler, __DIR__ . '/PhpFpm/php-fpm.conf');
$this->fpm = new FpmHandler($handler, 5000, __DIR__ . '/PhpFpm/php-fpm.conf');
$this->fpm->start();
}
}