Skip to content

Commit

Permalink
Conditionally use pcntl extension in inertia:start-ssr command (#492
Browse files Browse the repository at this point in the history
)

* Add pcntl to requirements

* Move ext-pcntl to suggest and add check to StartSsr command

* Tweak `ext-pcntl` suggestion message

* Update `inertia:start-ssr` command to only use `pcntl` when it's available

Co-authored-by: Jonathan Reinink <jonathan@reinink.ca>
  • Loading branch information
RobertBoes and reinink authored Jan 17, 2023
1 parent 5106f9d commit b983c6e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
"mockery/mockery": "^1.3.3",
"phpunit/phpunit": "^8.0|^9.5.8"
},
"suggest": {
"ext-pcntl": "Recommended when running the Inertia SSR server via the `inertia:start-ssr` artisan command."
},
"extra": {
"laravel": {
"providers": [
Expand Down
16 changes: 9 additions & 7 deletions src/Commands/StartSsr.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,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) {
Expand Down

0 comments on commit b983c6e

Please sign in to comment.