Skip to content

Documented the use of PHP streams as the process input #9105

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

Merged
merged 1 commit into from
Jan 23, 2018
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
24 changes: 24 additions & 0 deletions components/process.rst
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,29 @@ stream resources or Traversable objects as argument. As shown in the above examp
you need to explicitly call the :method:`Symfony\\Component\\Process\\InputStream::close`
method when you are done writing to the standard input of the subprocess.

Using PHP Streams as the Standard Input of a Process
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The input of a process can also be defined using `PHP streams`_::

$stream = fopen('php://temporary', 'w+');

$process = new Process('cat');
$process->setInput($stream);
$process->start();

fwrite($stream, 'foo');

// ... read process output or do other things

fwrite($stream, 'bar');
fclose($stream);

$process->wait();

// will echo: 'foobar'
echo $process->getOutput();

Stopping a Process
------------------

Expand Down Expand Up @@ -420,3 +443,4 @@ Use :method:`Symfony\\Component\\Process\\Process::disableOutput` and
.. _`pid`: https://en.wikipedia.org/wiki/Process_identifier
.. _`PHP Documentation`: http://php.net/manual/en/pcntl.constants.php
.. _Packagist: https://packagist.org/packages/symfony/process
.. _`PHP streams`: http://www.php.net/manual/en/book.stream.php