2024-05-06 20:40:05 +00:00
|
|
|
---
|
2024-10-30 17:04:36 +00:00
|
|
|
date: 20201117
|
2024-05-06 20:40:05 +00:00
|
|
|
id: 1aeeea82-1193-447d-95ae-4196175d6721
|
|
|
|
title: Console Signals
|
|
|
|
---
|
|
|
|
|
|
|
|
# Description
|
|
|
|
|
|
|
|
Symfony supports console signals[^1].
|
|
|
|
|
|
|
|
# Syntax
|
|
|
|
|
|
|
|
``` php
|
|
|
|
// ...
|
|
|
|
use Symfony\Component\Console\Command\SignalableCommandInterface;
|
|
|
|
|
|
|
|
class SignalCommand extends Command implements SignalableCommandInterface
|
|
|
|
{
|
|
|
|
// ...
|
|
|
|
|
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int
|
|
|
|
{
|
|
|
|
// ...
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getSubscribedSignals(): array
|
|
|
|
{
|
|
|
|
// return here any of the constants defined by PCNTL extension
|
|
|
|
// https://www.php.net/manual/en/pcntl.constants.php
|
|
|
|
return [SIGINT, SIGTERM];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function handleSignal(int $signal)
|
|
|
|
{
|
|
|
|
if (SIGINT === $signal) {
|
|
|
|
// ...
|
|
|
|
}
|
|
|
|
|
|
|
|
// ...
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
# Footnotes
|
|
|
|
|
|
|
|
[^1]: <https://en.wikipedia.org/wiki/Signal_(IPC)>
|