From 64de236889dfef6f4599dd3732076f7a3dcc17be Mon Sep 17 00:00:00 2001 From: Tristan Bessoussa Date: Tue, 22 Nov 2016 12:58:01 +0100 Subject: [PATCH 1/8] 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/8] 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/8] 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:: From 317b6edf1967d105deadfa55356778e1832bca49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20=C5=81ebkowski?= Date: Fri, 10 Feb 2017 12:36:04 +0100 Subject: [PATCH 4/8] add warning about `auto_alias` is not enabled by default --- reference/dic_tags.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/reference/dic_tags.rst b/reference/dic_tags.rst index 86713d3fcb7..f6dc316c4c3 100644 --- a/reference/dic_tags.rst +++ b/reference/dic_tags.rst @@ -353,6 +353,11 @@ wrapping their names with ``%`` characters). sense most of the times to prevent accessing those services directly instead of using the generic service alias. +.. note:: + + You need to manually add the ``Symfony\Component\DependencyInjection\Compiler\AutoAliasServicePass`` + compiler pass to the container for this feature to work. + console.command --------------- From c877fcea54cbf55336b2aca3f6b919156ffc1421 Mon Sep 17 00:00:00 2001 From: Vico Dambeck Date: Thu, 1 Sep 2016 12:03:26 +0200 Subject: [PATCH 5/8] change request factory example code --- components/http_foundation.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/components/http_foundation.rst b/components/http_foundation.rst index 9b80132c0e6..fd2a128cd3b 100644 --- a/components/http_foundation.rst +++ b/components/http_foundation.rst @@ -293,6 +293,7 @@ methods or changing some default behavior might help. In that case, register a PHP callable that is able to create an instance of your ``Request`` class:: use Symfony\Component\HttpFoundation\Request; + use AppBundle\Classes\SpecialRequest; Request::setFactory(function ( array $query = array(), @@ -303,7 +304,7 @@ PHP callable that is able to create an instance of your ``Request`` class:: array $server = array(), $content = null ) { - return SpecialRequest::create( + return new SpecialRequest( $query, $request, $attributes, From da454cdb5af867ed50a9c0d9cec250105eace170 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Mon, 13 Mar 2017 09:57:57 +0100 Subject: [PATCH 6/8] [#6939] some minor tweaks --- components/http_foundation.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/http_foundation.rst b/components/http_foundation.rst index fd2a128cd3b..afd7aea4fa2 100644 --- a/components/http_foundation.rst +++ b/components/http_foundation.rst @@ -292,8 +292,8 @@ represents an HTTP message. But when moving from a legacy system, adding methods or changing some default behavior might help. In that case, register a PHP callable that is able to create an instance of your ``Request`` class:: + use AppBundle\Http\SpecialRequest; use Symfony\Component\HttpFoundation\Request; - use AppBundle\Classes\SpecialRequest; Request::setFactory(function ( array $query = array(), @@ -304,7 +304,7 @@ PHP callable that is able to create an instance of your ``Request`` class:: array $server = array(), $content = null ) { - return new SpecialRequest( + return SpecialRequest::create( $query, $request, $attributes, From d2a1c235d2e2756c744ddea1e8efb9bbf3452b65 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Mon, 13 Mar 2017 10:07:14 +0100 Subject: [PATCH 7/8] [#7159] some minor tweaks --- components/process.rst | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/components/process.rst b/components/process.rst index 8c274914b21..091f8e4d1ce 100644 --- a/components/process.rst +++ b/components/process.rst @@ -126,22 +126,23 @@ are done doing other stuff:: .. 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 a ``Response`` is sent **before** a child process 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 as running a process that survives it parent process. - 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``. + If you want your process to survive the request/response cycle, you can + take advantage of the ``kernel.terminate`` event, and run your command + **synchronously** inside this event. Be aware that ``kernel.terminate`` + is called only if you use 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. + Beware also that if you do that, the said PHP-FPM process will not be + available to serve any new request until the subprocess is finished. This + means you can quickly block your FPM pool if you're not careful enough. + That is why it's generally way better not to do any fancy things even + after the request is sent, but to use a job queue instead. :method:`Symfony\\Component\\Process\\Process::wait` takes one optional argument: a callback that is called repeatedly whilst the process is still running, passing From 814d8c4d7251f822876a2a8607a5dbb0be55aab1 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Mon, 13 Mar 2017 11:04:13 +0100 Subject: [PATCH 8/8] [#7159] typo fix --- components/process.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/process.rst b/components/process.rst index 091f8e4d1ce..6220f662062 100644 --- a/components/process.rst +++ b/components/process.rst @@ -129,7 +129,7 @@ are done doing other stuff:: If a ``Response`` is sent **before** a child process 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 as running a process that survives it parent process. + is not the same as running a process that survives its parent process. If you want your process to survive the request/response cycle, you can take advantage of the ``kernel.terminate`` event, and run your command