Skip to content

Commit 699d8f6

Browse files
committed
Merge branch '5.4' into 6.0
* 5.4: Reword [Messenger] document reset_on_message transport option
2 parents f26a137 + fd38755 commit 699d8f6

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

logging.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,8 @@ defined.
167167
from the two files cannot be merged because the order matters and a merge does
168168
not allow to control the order.
169169

170+
.. _logging-handler-fingers_crossed:
171+
170172
Handlers that Modify Log Entries
171173
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
172174

messenger.rst

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,72 @@ of the desired grace period in seconds) in order to perform a graceful shutdown:
687687
[program:x]
688688
stopwaitsecs=20
689689
690+
Stateless Worker
691+
~~~~~~~~~~~~~~~~
692+
693+
PHP is designed to be stateless, there are no shared resources across different
694+
requests. In HTTP context PHP cleans everything after sending the response, so
695+
you can decide to not take care of services that may leak memory.
696+
697+
On the other hand, workers usually run in long-running CLI processes, which don't
698+
finish after processing a message. That's why you need to be careful about services
699+
state to not leak information and/or memory from one message to another message.
700+
701+
However, certain Symfony services, such as the Monolog
702+
:ref:`fingers crossed handler <logging-handler-fingers_crossed>`, leak by design.
703+
In those cases, use the ``reset_on_message`` transport option to automatically
704+
reset the service container between two messages:
705+
706+
.. configuration-block::
707+
708+
.. code-block:: yaml
709+
710+
# config/packages/messenger.yaml
711+
framework:
712+
messenger:
713+
transports:
714+
async:
715+
dsn: '%env(MESSENGER_TRANSPORT_DSN)%'
716+
reset_on_message: true
717+
718+
.. code-block:: xml
719+
720+
<!-- config/packages/messenger.xml -->
721+
<?xml version="1.0" encoding="UTF-8" ?>
722+
<container xmlns="http://symfony.com/schema/dic/services"
723+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
724+
xmlns:framework="http://symfony.com/schema/dic/symfony"
725+
xsi:schemaLocation="http://symfony.com/schema/dic/services
726+
https://symfony.com/schema/dic/services/services-1.0.xsd
727+
http://symfony.com/schema/dic/symfony
728+
https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
729+
730+
<framework:config>
731+
<framework:messenger>
732+
<framework:transport name="async" dsn="%env(MESSENGER_TRANSPORT_DSN)%" reset-on-message="true">
733+
</framework:transport>
734+
</framework:messenger>
735+
</framework:config>
736+
</container>
737+
738+
.. code-block:: php
739+
740+
// config/packages/messenger.php
741+
use Symfony\Config\FrameworkConfig;
742+
743+
return static function (FrameworkConfig $framework) {
744+
$messenger = $framework->messenger();
745+
746+
$messenger->transport('async')
747+
->dsn('%env(MESSENGER_TRANSPORT_DSN)%')
748+
->resetOnMessage(true)
749+
;
750+
};
751+
752+
.. versionadded:: 5.4
753+
754+
The ``reset_on_message`` option was introduced in Symfony 5.4.
755+
690756
.. _messenger-retries-failures:
691757

692758
Retries & Failures

0 commit comments

Comments
 (0)