You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: artisan.md
+14-32
Original file line number
Diff line number
Diff line change
@@ -615,47 +615,29 @@ If you would like to call another console command and suppress all of its output
615
615
<aname="signal-handling"></a>
616
616
## Signal Handling
617
617
618
-
The Symfony Console component, which powers the Artisan console, allows you to indicate which process signals (if any) your command handles. For example, you may indicate that your command handles the `SIGINT` and `SIGTERM` signals.
619
-
620
-
To get started, you should implement the `Symfony\Component\Console\Command\SignalableCommandInterface` interface on your Artisan command class. This interface requires you to define two methods: `getSubscribedSignals` and `handleSignal`:
621
-
622
-
```php
623
-
<?php
624
-
625
-
use Symfony\Component\Console\Command\SignalableCommandInterface;
626
-
627
-
class StartServer extends Command implements SignalableCommandInterface
628
-
{
629
-
// ...
630
-
631
-
/**
632
-
* Get the list of signals handled by the command.
633
-
*
634
-
* @return array
635
-
*/
636
-
public function getSubscribedSignals(): array
637
-
{
638
-
return [SIGINT, SIGTERM];
639
-
}
618
+
As you may know, operating systems allow signals to be sent to running processes. For example, the `SIGTERM` signal is how operating systems ask a program to terminate. If you wish to listen for signals in your Artisan console commands and execute code when they occur, you may use the `trap` method:
As you might expect, the `getSubscribedSignals` method should return an array of the signals that your command can handle, while the `handleSignal` method receives the signal and can respond accordingly.
634
+
To listen for multiple signals at once, you may provide an array of signals to the `trap` method:
635
+
636
+
$this->trap([SIGTERM, SIGQUIT], function ($signal) {
0 commit comments