Hacktoberfest 2026:維護者為十月標記出來的 issue,仍然開放、適合新手。 瀏覽 Hacktoberfest issue

Bug: CLI Commands do not respond to Ctrl-C interrupts (might be an enhancement not a bug)

未關閉
#10,589 3 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

還沒有人認領這個 Issue。

評估

難度
4/5
預估耗時
3-5 天
新手友好度
48/100
Issue 類型
缺陷
描述清晰度
基本清楚
活躍度
活躍
技術堆疊
php
領域
cli

研究方向

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 內容生成。

描述

bug
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

環境準備

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

codeigniter4/CodeIgniter4 的其他 Issue

查看 codeigniter4/CodeIgniter4 的全部 Issue

相似的 Issue

更多 PHP Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。