diff --git a/runtime/layers/fpm/bootstrap b/runtime/layers/fpm/bootstrap index e9378e44c..fa7215d07 100755 --- a/runtime/layers/fpm/bootstrap +++ b/runtime/layers/fpm/bootstrap @@ -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) { diff --git a/src/Event/Http/FpmHandler.php b/src/Event/Http/FpmHandler.php index 9925779c4..9c6c5967b 100644 --- a/src/Event/Http/FpmHandler.php +++ b/src/Event/Http/FpmHandler.php @@ -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; } @@ -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(); } diff --git a/tests/Handler/FpmHandlerLoadBalancerTest.php b/tests/Handler/FpmHandlerLoadBalancerTest.php index 404d35213..58ebff4b8 100644 --- a/tests/Handler/FpmHandlerLoadBalancerTest.php +++ b/tests/Handler/FpmHandlerLoadBalancerTest.php @@ -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(); } } diff --git a/tests/Handler/FpmHandlerTest.php b/tests/Handler/FpmHandlerTest.php index 00144fa98..96cb2a583 100644 --- a/tests/Handler/FpmHandlerTest.php +++ b/tests/Handler/FpmHandlerTest.php @@ -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 { @@ -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([ @@ -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(); } }