We can't find the internet
Attempting to reconnect
Something went wrong!
Hang in there while we get back on track
As you may know, you can use the shortcut Ctrl + C
in the console to terminate a process running in the foreground. It
interrupts the current foreground process by sending the SIGINT
signal to the process. Basically, this is just a
request to stop the current process. What is very good about it is that you can also intercept and process this signal
using PHP. Let's take a look how you can integrate it in your own console command:
<?php
public function handle()
{
// Do some stuff in your command
// Catch the cancellation (Ctrl+C)
pcntl_async_signals(true);
pcntl_signal(SIGINT, function () use ($master) {
$this->line('You pressed Ctrl + C');
});
}
If this post was enjoyable or useful for you, please share it! If you have comments, questions, or feedback, you can email my personal email. To get new posts, subscribe use the RSS feed.