Skip to content

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

Open
mdalikadar wants to merge 4 commits into
codeigniter4:4.8from
mdalikadar:feat/signaltrait-windows-ctrl-c
Open

mdalikadar wants to merge 4 commits into
codeigniter4:4.8from
mdalikadar:feat/signaltrait-windows-ctrl-c

Conversation

@mdalikadar

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.

Refs #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 the 4.8 PRs that target the `4.8` branch. label Nov 1, 2026

This branch has not been deployed

No deployments
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.

1 participant