Bug: CLI Commands do not respond to Ctrl-C interrupts (might be an enhancement not a bug)
維護者通常 1 天內回覆
還沒有人認領這個 Issue。
評估
研究方向
Start by reproducing the issue with the long-running command shown in the report on Windows CLI. Review how a command's run(array $params) method is invoked and how CLI::write and CLI::error are used, then compare the reported sapi_windows_set_ctrl_handler and pcntl_signal approaches. Done means Ctrl-C reliably halts the command with a clear abort message on supported platforms, with coverage for the relevant behavior.
由索引模型根據 Issue 內容生成。
描述
PHP Version
8.4
CodeIgniter4 Version
4.7.4
CodeIgniter4 Installation Method
Composer (using codeigniter4/appstarter)
Which operating systems have you tested for this bug?
Windows
Which server did you use?
cli-server (PHP built-in webserver)
Environment
development
Database
MySQL 8.4.9
What happened?
CLI commands do not respond to the user pressing Ctrl-C to abort
Steps to Reproduce
Create a long running or infinite loop as a command and try and press Ctrl-C. For example:
public function run(array $params)
{
while ( 1 > 0 ) {
CLI::write("Waiting...");
}
}
Expected Output
I expected the execution to halt.
Anything else?
I have (with Claude's assistance) implemented the following workaround which should possibly be included in the core.
public function run(array $params)
{
// Abort on Ctrl-C
if (function_exists('sapi_windows_set_ctrl_handler')) {
// Windows
sapi_windows_set_ctrl_handler(function ($event) {
if ($event === PHP_WINDOWS_EVENT_CTRL_C) {
CLI::error("\nProcess aborted by Ctrl-C.");
exit(1);
}
});
} else if (function_exists('pcntl_signal')) {
// Linux / macOS fallback
pcntl_async_signals(true);
pcntl_signal(SIGINT, function() {
CLI::error("\nProcess aborted by Ctrl-C.");
exit(1);
});
}
...
- 主要語言
- PHP
- 星號
- 6k
- 分支
- 2k
- 平均合併
- 1 天 22 小時
- 30 天內合併 PR
- 59
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
codeigniter4/CodeIgniter4 的其他 Issue
-
難度 2/5 1-3 小時 新手友好度 72/100
codeigniter4/CodeIgniter4#10616 · 1 則留言 ·
維護者通常 1 天內回覆
-
難度 4/5 3-5 天 新手友好度 35/100
codeigniter4/CodeIgniter4#10618 ·
維護者通常 1 天內回覆
-
難度 3/5 1-2 天 新手友好度 62/100
codeigniter4/CodeIgniter4#10617 · 1 則留言 ·
維護者通常 1 天內回覆
-
難度 4/5 3-5 天 新手友好度 25/100
codeigniter4/CodeIgniter4#10615 · 1 則留言 ·
維護者通常 1 天內回覆
-
dev
難度 5/5 一週以上 新手友好度 25/100
codeigniter4/CodeIgniter4#10427 · 5 則留言 ·
維護者通常 1 天內回覆
查看 codeigniter4/CodeIgniter4 的全部 Issue
相似的 Issue
-
難度 2/5 1-3 小時 新手友好度 70/100
-
難度 2/5 1-3 小時 新手友好度 78/100
matomo-org/device-detector#8405 ·
維護者通常 1 天內回覆
-
bug
難度 2/5 1-3 小時 新手友好度 66/100
維護者通常 1 天內回覆
-
sync-en
難度 2/5 1-3 小時 新手友好度 62/100
維護者通常 1 天內回覆
-
sync-en
難度 2/5 1-3 小時 新手友好度 66/100
維護者通常 4 天內回覆