You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit d105e10
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: docs/changelogs/v4.8.0.md
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -223,6 +223,7 @@ Release Date: Unreleased
223
223
- Likewise, the `command()` function now also supports the above enhancements for command-line option parsing when using the function to run commands from code.
224
224
- Added `make:request` generator command to scaffold [Form Request](../incoming/form_requests.md#form-requests) classes.
225
225
- Added `key:rotate` command to demote the current `encryption.key` to `encryption.previousKeys` in **.env** and generate a new key. See [Rotating with the `key:rotate` Command](../libraries/encryption.md#rotating-with-the-keyrotate-command).
226
+
-`SignalTrait` now handles Ctrl+C and Ctrl+Break on Windows, through `sapi_windows_set_ctrl_handler()`, so a command can stop gracefully there too. The events are reported as `SIGINT` (`2`). See [Windows](../cli/cli_signals.md#windows).
226
227
- Added `AbstractCommand::callSilently()` to invoke another command with its output discarded, restoring the prior output afterwards. See [Calling Silently](../cli/cli_modern_commands.md#calling-silently).
227
228
- The output side of the `CLI` class now lives in instance classes, with `CLI` delegating to them: `Output` (`print()`, `write()`, `error()`, `newLine()`, `deferNewLine()`, `beep()`, `clearScreen()`, `color()`, `wrap()`), `Terminal` (dimensions and color support), `ProgressBar`, `Table`, and `Color` (ANSI codes and `Color::width()`). `CLI::getOutput()` and `CLI::getTerminal()` return the shared instances. See [The Classes Behind the Facade](../cli/cli_library.md#the-classes-behind-the-facade).
228
229
- Modern commands can write through `$this->getOutput()`, the same `Output` used by the static `CLI` methods. `AbstractCommand::run()` and `Commands::runCommand()` accept an `Output` to run against, which `Console` passes down and sub-commands inherit. See [Writing Output](../cli/cli_modern_commands.md#writing-output).
Copy file name to clipboardExpand all lines: docs/cli/cli_signals.md
+20-4Lines changed: 20 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -36,13 +36,29 @@ These signals are handled directly by the kernel and will terminate or suspend y
36
36
37
37
Signal handling requires:
38
38
39
-
-**Unix-based system** (Linux, macOS, BSD) - Windows is not supported
40
-
-**PCNTL extension** - for signal registration and handling
41
-
-**POSIX extension** - required for pause/resume functionality (SIGTSTP/SIGCONT)
39
+
-**Unix-based system** (Linux, macOS, BSD) - see [Windows](#windows) for Windows
40
+
-**PCNTL extension**(Unix only) - for signal registration and handling
41
+
-**POSIX extension**(Unix only) - required for pause/resume functionality (SIGTSTP/SIGCONT)
42
42
43
43
!!! note "Note"
44
44
On systems without these extensions, the SignalTrait will gracefully degrade and disable signal handling.
45
45
46
+
### Windows
47
+
48
+
!!! success "Available from version 4.8.0"
49
+
Ctrl+C and Ctrl+Break are handled on Windows.
50
+
51
+
Windows has no PCNTL extension and no Unix signals. `SignalTrait` handles the one thing Windows can deliver to a PHP script: the console control events produced by **Ctrl+C** and **Ctrl+Break**. They are handled through PHP's `sapi_windows_set_ctrl_handler()` and reported to your command as `SIGINT` (`2`), so `isRunning()`, `shouldTerminate()`, custom handlers, and `onInterruption()` work as they do on Unix.
52
+
53
+
- Call `registerSignals()` without arguments. The `SIG*` constants come from the PCNTL extension, which is not available on Windows. If you pass a list, it must contain `2`. Every other signal is ignored.
54
+
- To map the event to your own method, use `2` as the key: `$this->registerSignals([], [2 => 'handleInterrupt']);`.
55
+
-`withSignalsBlocked()` runs the operation without blocking console events. Your handler can run during the operation, as soon as the event arrives.
56
+
- Pause and resume (`SIGTSTP` / `SIGCONT`), and every other signal, do not exist on Windows.
57
+
- Windows console control handling is available when PHP runs under `cli` or `cli-server`. On other SAPIs, for example when a command runs through `command()` in a controller, `registerSignals()` does nothing.
58
+
59
+
!!! important "Important"
60
+
Once a handler is registered, Ctrl+C and Ctrl+Break no longer end the process. Your command must check `shouldTerminate()` and return, as on Unix.
61
+
46
62
## Using the SignalTrait
47
63
48
64
The `SignalTrait` provides a comprehensive signal handling system for CLI commands. To use it, simply add the trait to your command class and register signals in your command's `execute()` method:
@@ -523,7 +539,7 @@ $this->registerSignals(
523
539
```
524
540
525
541
!!! note "Note"
526
-
Requires the PCNTL extension. On Windows, signal handling is automatically disabled.
542
+
On Unix, registration requires the PCNTL extension. On Windows, only Ctrl+C and Ctrl+Break are handled, as `SIGINT` (`2`). See [Windows](#windows).
0 commit comments