Hacktoberfest 2026: die Issues, die Maintainer für den Oktober markiert haben – offen und einsteigerfreundlich. Hacktoberfest-Issues durchsuchen

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

Offen
#10,589 3 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Anfängerfreundlichkeit
48/100
Issue-Typ
Bug
Klarheit
Größtenteils klar
Aktivitätsstatus
Aktiv
Tech-Stack
php
Bereich
cli

Rechercherichtung

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.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

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);
		});
	}
	...
Vorherrschende Sprache
PHP
Sterne
6k
Forks
2k
Ø Merge
1 T. 22 Std.
Gemergte PRs (30 T.)
59

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus codeigniter4/CodeIgniter4

Alle Issues in codeigniter4/CodeIgniter4

Ähnliche Issues

Weitere Issues zu PHP

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.