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 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-Cto abortSteps to Reproduce
Create a long running or infinite loop as a command and try and press
Ctrl-C. For example: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.