From 81e15dfbf216b6f3e3cb85347b91e5b4819dc7c0 Mon Sep 17 00:00:00 2001 From: Robert Boes <2871897+RobertBoes@users.noreply.github.com> Date: Sun, 15 Jan 2023 21:07:20 +0100 Subject: [PATCH 1/4] Add pcntl to requirements --- composer.json | 1 + 1 file changed, 1 insertion(+) diff --git a/composer.json b/composer.json index 5b3b35ec..9648bd63 100644 --- a/composer.json +++ b/composer.json @@ -27,6 +27,7 @@ "require": { "php": "^7.2|~8.0.0|~8.1.0|~8.2.0", "ext-json": "*", + "ext-pcntl": "*", "laravel/framework": "^6.0|^7.0|^8.74|^9.0|^10.0" }, "require-dev": { From a6252bd283bf2a92bfa10b3a2b44596e8b716ec1 Mon Sep 17 00:00:00 2001 From: Robert Boes <2871897+RobertBoes@users.noreply.github.com> Date: Mon, 16 Jan 2023 11:06:14 +0100 Subject: [PATCH 2/4] Move ext-pcntl to suggest and add check to StartSsr command --- composer.json | 4 +++- src/Commands/StartSsr.php | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 9648bd63..1b5aaac5 100644 --- a/composer.json +++ b/composer.json @@ -27,7 +27,6 @@ "require": { "php": "^7.2|~8.0.0|~8.1.0|~8.2.0", "ext-json": "*", - "ext-pcntl": "*", "laravel/framework": "^6.0|^7.0|^8.74|^9.0|^10.0" }, "require-dev": { @@ -36,6 +35,9 @@ "mockery/mockery": "^1.3.3", "phpunit/phpunit": "^8.0|^9.5.8" }, + "suggest": { + "ext-pcntl": "Required to run Inertia SSR through the inertia:start-ssr artisan command" + }, "extra": { "laravel": { "providers": [ diff --git a/src/Commands/StartSsr.php b/src/Commands/StartSsr.php index 18efdee7..7fa51306 100644 --- a/src/Commands/StartSsr.php +++ b/src/Commands/StartSsr.php @@ -28,6 +28,12 @@ class StartSsr extends Command */ public function handle(): int { + if (! extension_loaded('pcntl')) { + $this->error('The pcntl PHP extension (ext-pcntl) is required to run Inertia SSR.'); + + return self::FAILURE; + } + if (! config('inertia.ssr.enabled', true)) { $this->error('Inertia SSR is not enabled. Enable it via the `inertia.ssr.enabled` config option.'); From 3919fec91e2395a632136787179f80f308270230 Mon Sep 17 00:00:00 2001 From: Jonathan Reinink Date: Mon, 16 Jan 2023 19:58:03 -0500 Subject: [PATCH 3/4] Tweak `ext-pcntl` suggestion message --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 1b5aaac5..d954c098 100644 --- a/composer.json +++ b/composer.json @@ -36,7 +36,7 @@ "phpunit/phpunit": "^8.0|^9.5.8" }, "suggest": { - "ext-pcntl": "Required to run Inertia SSR through the inertia:start-ssr artisan command" + "ext-pcntl": "Recommended when running the Inertia SSR server via the `inertia:start-ssr` artisan command." }, "extra": { "laravel": { From 414ca64aa9c54197cca5e708b98285247e1ee58b Mon Sep 17 00:00:00 2001 From: Jonathan Reinink Date: Mon, 16 Jan 2023 19:59:10 -0500 Subject: [PATCH 4/4] Update `inertia:start-ssr` command to only use `pcntl` when it's available --- src/Commands/StartSsr.php | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/src/Commands/StartSsr.php b/src/Commands/StartSsr.php index 7fa51306..e2b5d84b 100644 --- a/src/Commands/StartSsr.php +++ b/src/Commands/StartSsr.php @@ -28,12 +28,6 @@ class StartSsr extends Command */ public function handle(): int { - if (! extension_loaded('pcntl')) { - $this->error('The pcntl PHP extension (ext-pcntl) is required to run Inertia SSR.'); - - return self::FAILURE; - } - if (! config('inertia.ssr.enabled', true)) { $this->error('Inertia SSR is not enabled. Enable it via the `inertia.ssr.enabled` config option.'); @@ -62,13 +56,15 @@ public function handle(): int $process->setTimeout(null); $process->start(); - $stop = function () use ($process) { - $process->stop(); - }; - pcntl_async_signals(true); - pcntl_signal(SIGINT, $stop); - pcntl_signal(SIGQUIT, $stop); - pcntl_signal(SIGTERM, $stop); + if (extension_loaded('pcntl')) { + $stop = function () use ($process) { + $process->stop(); + }; + pcntl_async_signals(true); + pcntl_signal(SIGINT, $stop); + pcntl_signal(SIGQUIT, $stop); + pcntl_signal(SIGTERM, $stop); + } foreach ($process as $type => $data) { if ($process::OUT === $type) {