Skip to content

feat: handle Ctrl+C and Ctrl+Break in SignalTrait on Windows - #10699

Merged
michalsn merged 13 commits into
codeigniter4:4.8from
mdalikadar:feat/signaltrait-windows-ctrl-c
Nov 15, 2026
Merged

michalsn merged 13 commits into
codeigniter4:4.8from
mdalikadar:feat/signaltrait-windows-ctrl-c

Conversation

@mdalikadar

@mdalikadar mdalikadar commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Description
Adds Windows support to SignalTrait, as discussed in #10589. Without PCNTL, registerSignals() now installs a console control handler through sapi_windows_set_ctrl_handler(). It is reported to the command as SIGINT (2), because the SIG* constants come from PCNTL and are not available on Windows. A command can then stop gracefully on Ctrl+C or Ctrl+Break through shouldTerminate(), onInterruption() or a mapped method, as it does on Unix.

  • unregisterSignals() removes the handler.
  • getSignalName() no longer touches the SIG* constants without PCNTL, so getProcessState() works there.
  • withSignalsBlocked() stays a no-op on Windows, which is documented.
  • The native function sits behind a small protected wrapper so tests can replace it. The new tests run on any OS.

Closes #10589

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value (without duplication)
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@carson-codeigniter4 carson-codeigniter4 Bot added 4.8 PRs that target the `4.8` branch. stale Pull requests with conflicts labels Nov 1, 2026
@carson-codeigniter4

This comment has been minimized.

@mdalikadar
mdalikadar force-pushed the feat/signaltrait-windows-ctrl-c branch from d93de33 to 965afec Compare November 5, 2026 02:23
@carson-codeigniter4 carson-codeigniter4 Bot removed the stale Pull requests with conflicts label Nov 5, 2026
@paulbalandan
paulbalandan requested a balanced review from Copilot November 5, 2026 13:10

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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

Comment thread system/CLI/SignalTrait.php Resolved
Comment thread tests/system/CLI/SignalWindowsTest.php Resolved
Comment thread system/CLI/SignalTrait.php Resolved
Comment thread system/CLI/SignalTrait.php Resolved
Comment thread system/CLI/SignalTrait.php Resolved
Comment thread system/CLI/SignalTrait.php Resolved
Comment thread docs/cli/cli_signals.md Resolved
Comment thread docs/cli/cli_signals.md Resolved
Comment thread docs/cli/cli_signals.md Resolved
Comment thread docs/cli/cli_signals.md Resolved
Comment thread docs/cli/cli_signals.md Resolved
Comment thread system/CLI/SignalTrait.php Resolved
Comment thread system/CLI/SignalTrait.php Resolved
Comment thread system/CLI/SignalTrait.php Resolved

@paulbalandan paulbalandan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@michalsn michalsn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, but I have to ask: have you actually tested this on a Windows machine?

@mdalikadar

Copy link
Copy Markdown
Contributor Author

Looks good, but I have to ask: have you actually tested this on a Windows machine?

i have tested it.

image

@michalsn michalsn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@michalsn
michalsn merged commit d105e10 into codeigniter4:4.8 Nov 15, 2026
59 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

4.8 PRs that target the `4.8` branch.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants