Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

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

Aperta
#10,589 3 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
48/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
php
Ambito
cli

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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);
		});
	}
	...
Lingua principale
PHP
Stelle
6k
Fork
2k
Merge medio
1g 22h
PR unite (30g)
59

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di codeigniter4/CodeIgniter4

Tutte le issue di codeigniter4/CodeIgniter4

Issue simili

Altre issue su PHP

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.