New in Symfony 7.1: POSIX Signals Improvements
May 22, 2024 • Published by Javier Eguiluz
Symfony 7.1 is backed by:
Signals are standardized messages sent to a running program to trigger specific behaviors, such as quitting or handling errors. POSIX signals are a standardized list of signals used in operating systems like Linux and macOS. In Symfony 7.1 we've made some improvements related to signals.
Allow Ignoring Signals when Running Processes
Imagine that you're running a handler for Messenger component messages and
you run some process (via the Process component) inside the handler. If the
handler receives a SIGTERM
signal (which requests the termination of the process)
the handler would fail with a ProcessSignaledException
instead of waiting for
the process to terminate and shut down gracefully.
In Symfony 7.1 we've added a setIgnoredSignals()
method so processes can define
a list of signals to ignore:
1 2 3 4
use Symfony\Component\Process\Process;
$process = new Process(['find', '/', '-name', '...']);
$process->setIgnoredSignals([SIGKILL, SIGUSR1]);
Handle SIGQUIT
Signal in Console and Messenger
PHP-FPM and Nginx use the SIGQUIT
signal for graceful shutdown. If you run
your PHP application inside a Docker container and use the official PHP and nginx
images, you need to handle this signal because those images override the default
Docker shutdown signal to use SIGQUIT
.
That's why in Symfony 7.1 we've updated the Console component to subscribe to
the SIGQUIT
signal in addition to the SIGINT
and SIGTERM
signals.
The Messenger component was also updated to add SIGQUIT
to the list of
signals that gracefully shut down the messenger:consume
and messenger:failed:retry
commands.
Help the Symfony project!
As with any Open-Source project, contributing code or documentation is the most common way to help, but we also have a wide range of sponsoring opportunities.
Comments are closed.
To ensure that comments stay relevant, they are closed for old posts.