Repository navigation
feat: handle Ctrl+C and Ctrl+Break in SignalTrait on Windows - #10699
Open
mdalikadar wants to merge 4 commits into
Open
mdalikadar wants to merge 4 commits into
mdalikadar wants to merge 4 commits into
Conversation
This comment has been minimized.
This comment has been minimized.
mdalikadar
force-pushed
the
feat/signaltrait-windows-ctrl-c
branch
from
November 5, 2026 02:23
d93de33 to
965afec
Compare
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Windows signal handling has unresolved callback-access failures, unsupported web-SAPI registration, and resource-retention defects, while the no-backend test can still install a native handler.
4 open issues
What changed in this PR
Adds Windows console-event support to SignalTrait, addressing #10589 by letting CLI commands handle Ctrl+C and Ctrl+Break through the existing graceful-termination APIs.
Changes:
- Registers and removes Windows console handlers, reporting both events as
SIGINT(2). - Adds simulated Windows tests for registration, dispatch, cleanup, and operation without PCNTL.
- Documents Windows usage and limitations in the user guide and v4.8.0 changelog.
Validation used focused source inspection; runtime tests and full validation remain for CI.
| File | Description |
|---|---|
tests/system/CLI/SignalWindowsTest.php |
Tests Windows signal behavior using simulated handlers. |
tests/_support/Commands/Legacy/SignalCommandWindows.php |
Provides a Windows handler test double. |
system/CLI/SignalTrait.php |
Adds Windows registration, event dispatch, cleanup, and signal naming. |
docs/cli/cli_signals.md |
Explains Windows usage and signal-blocking limitations. |
docs/changelogs/v4.8.0.md |
Announces Windows console-event support. |
Review effort: Balanced
| { | ||
| // Static analysis on other platforms does not know the function. | ||
| /** @psalm-suppress UndefinedFunction */ | ||
| return sapi_windows_set_ctrl_handler($handler, $add); // @codeCoverageIgnore |
| { | ||
| // Neither PCNTL nor a console control handler: Unix without PCNTL, or Windows | ||
| // before sapi_windows_set_ctrl_handler() existed. | ||
| $command = new SignalCommandNoPcntl(service('logger'), service('commands')); |
| */ | ||
| protected function isWindowsCtrlHandlerAvailable(): bool | ||
| { | ||
| return is_windows() && function_exists('sapi_windows_set_ctrl_handler'); |
| protected function unregisterSignals(): void | ||
| { | ||
| if ($this->windowsCtrlHandlerRegistered) { | ||
| $this->setWindowsCtrlHandler([$this, 'handleWindowsCtrlEvent'], false); |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Description
Adds Windows support to
SignalTrait, as discussed in #10589. Without PCNTL,registerSignals()now installs a console control handler throughsapi_windows_set_ctrl_handler(). It is reported to the command asSIGINT(2), because theSIG*constants come from PCNTL and are not available on Windows. A command can then stop gracefully on Ctrl+C or Ctrl+Break throughshouldTerminate(),onInterruption()or a mapped method, as it does on Unix.unregisterSignals()removes the handler.getSignalName()no longer touches theSIG*constants without PCNTL, sogetProcessState()works there.withSignalsBlocked()stays a no-op on Windows, which is documented.Refs #10589
Checklist: