Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Process] Add explanation on how to make the Process survive a response #7159

Merged
merged 3 commits into from
Mar 13, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions components/process.rst
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,25 @@ 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``.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want me to add a note to include this remark ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think that's an important note that should be added inside a caution block.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xabbuh done !


.. caution::

Beware also that if you do that, the said php process won't available to serve
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

won't be

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's generally

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::
Expand Down