From 64de236889dfef6f4599dd3732076f7a3dcc17be Mon Sep 17 00:00:00 2001 From: Tristan Bessoussa Date: Tue, 22 Nov 2016 12:58:01 +0100 Subject: [PATCH 1/3] Add explanation how to make the Process survive a response Fixes #7151 It confuses user that could be tempted to use the Asynchronous Process feature to achieve long running task after the Response is sent. The result is the following : from no code execution (if you send a Response really fast) to partial code execution --- components/process.rst | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/components/process.rst b/components/process.rst index 551ea391ab8..9f4cc194563 100644 --- a/components/process.rst +++ b/components/process.rst @@ -124,6 +124,16 @@ are done doing other stuff:: which means that your code will halt at this line until the external process is completed. +.. note:: + If a `Response` is sent **before** what `Process` is running had a chance to complete, + the server process will be killed (depending on your OS). It means that your task + will be stopped right away. + Running an asynchronous process is not the same than running a processing surviving yourselves. + + If you want your process to survive the request/response cycle, you could take + advantage of the `kernel.terminate` event, and run your command **synchronuously** + inside this event. Be aware that `kernel.terminate` is called only if you run `PHP-FPM`. + :method:`Symfony\\Component\\Process\\Process::wait` takes one optional argument: a callback that is called repeatedly whilst the process is still running, passing in the output and its type:: From 020f1b71b5d3cd9e40fa14213dfa0a638af04268 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Fri, 25 Nov 2016 12:50:15 +0100 Subject: [PATCH 2/3] Fixed some syntax issues --- components/process.rst | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/components/process.rst b/components/process.rst index 9f4cc194563..497b6c31018 100644 --- a/components/process.rst +++ b/components/process.rst @@ -125,14 +125,15 @@ are done doing other stuff:: process is completed. .. note:: - If a `Response` is sent **before** what `Process` is running had a chance to complete, + + If a ``Response`` is sent **before** what ``Process`` is running had a chance to complete, the server process will be killed (depending on your OS). It means that your task - will be stopped right away. - Running an asynchronous process is not the same than running a processing surviving yourselves. + will be stopped right away. Running an asynchronous process is not the same than running + a processing surviving yourselves. If you want your process to survive the request/response cycle, you could take - advantage of the `kernel.terminate` event, and run your command **synchronuously** - inside this event. Be aware that `kernel.terminate` is called only if you run `PHP-FPM`. + advantage of the ``kernel.terminate`` event, and run your command **synchronuously** + inside this event. Be aware that ``kernel.terminate`` is called only if you run ``PHP-FPM``. :method:`Symfony\\Component\\Process\\Process::wait` takes one optional argument: a callback that is called repeatedly whilst the process is still running, passing From cdf248c04dc7262571513d63d8b65b8ac37e49a6 Mon Sep 17 00:00:00 2001 From: Tristan Bessoussa Date: Fri, 16 Dec 2016 12:29:24 +0100 Subject: [PATCH 3/3] add a caution block about php-fpm pool --- components/process.rst | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/components/process.rst b/components/process.rst index 497b6c31018..ebd5c97d48e 100644 --- a/components/process.rst +++ b/components/process.rst @@ -135,6 +135,14 @@ are done doing other stuff:: advantage of the ``kernel.terminate`` event, and run your command **synchronuously** inside this event. Be aware that ``kernel.terminate`` is called only if you run ``PHP-FPM``. +.. caution:: + + Beware also that if you do that, the said php process won't available to serve + any new request until the subprocess is finished, which means you can block your + FPM pool quickly if you're not careful enough. + That's why it generally way better to not do any fancy thing even after the request is sent + but prefer using a job queue. + :method:`Symfony\\Component\\Process\\Process::wait` takes one optional argument: a callback that is called repeatedly whilst the process is still running, passing in the output and its type::