8000 minor #7159 [Process] Add explanation on how to make the Process surv… · ScreamZ/symfony-docs@01ebdc3 · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit 01ebdc3

Browse files
committed
minor symfony#7159 [Process] Add explanation on how to make the Process survive a response (tristanbes, javiereguiluz)
This PR was merged into the 2.7 branch. Discussion ---------- [Process] Add explanation on how to make the Process survive a response Fixes symfony#7151 It clarifies the situation for users that could be tempted to use the asynchronous `Process` feature to achieve long running task after the Response is sent which won't work. It goes from no code execution (if you send a Response really fast) to partial code execution. Commits ------- cdf248c add a caution block about php-fpm pool 020f1b7 Fixed some syntax issues 64de236 Add explanation how to make the Process survive a response
2 parents da454cd + cdf248c commit 01ebdc3

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

components/process.rst

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,25 @@ are done doing other stuff::
124124
which means that your code will halt at this line until the external
125125
process is completed.
126126

127+
.. note::
128+
129+
If a ``Response`` is sent **before** what ``Process`` is running had a chance to complete,
130+
the server process will be killed (depending on your OS). It means that your task
131+
will be stopped right away. Running an asynchronous process is not the same than running
132+
a processing surviving yourselves.
133+
134+
If you want your process to survive the request/response cycle, you could take
135+
advantage of the ``kernel.terminate`` event, and run your command **synchronuously**
136+
inside this event. Be aware that ``kernel.terminate`` is called only if you run ``PHP-FPM``.
137+
138+
.. caution::
139+
140+
Beware also that if you do that, the said php process won't available to serve
141+
any new request until the subprocess is finished, which means you can block your
142+
FPM pool quickly if you're not careful enough.
143+
That's why it generally way better to not do any fancy thing even after the request is sent
144+
but prefer using a job queue.
145+
127146
:method:`Symfony\\Component\\Process\\Process::wait` takes one optional argument:
128147
a callback that is called repeatedly whilst the process is still running, passing
129148
in the output and its type::

0 commit comments

Comments
 (0)
0