8000 minor #9105 Documented the use of PHP streams as the process input (j… · symfony/symfony-docs@82e205c · GitHub
[go: up one dir, main page]

Skip to content

Commit 82e205c

Browse files
committed
minor #9105 Documented the use of PHP streams as the process input (javiereguiluz)
This PR was merged into the 3.3 branch. Discussion ---------- Documented the use of PHP streams as the process input This fixes #3955 ... and goes to 3.3 branch instead of 2.7 because 3.3 is the first one that contains the needed parent section `Streaming to the Standard Input of a Process`. Commits ------- 3e3da59 Documented the use of PHP streams as the process input
2 parents 351f6db + 3e3da59 commit 82e205c

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

components/process.rst

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,29 @@ stream resources or Traversable objects as argument. As shown in the above examp
230230
you need to explicitly call the :method:`Symfony\\Component\\Process\\InputStream::close`
231231
method when you are done writing to the standard input of the subprocess.
232232

233+
Using PHP Streams as the Standard Input of a Process
234+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
235+
236+
The input of a process can also be defined using `PHP streams`_::
237+
238+
$stream = fopen('php://temporary', 'w+');
239+
240+
$process = new Process('cat');
241+
$process->setInput($stream);
242+
$process->start();
243+
244+
fwrite($stream, 'foo');
245+
246+
// ... read process output or do other things
247+
248+
fwrite($stream, 'bar');
249+
fclose($stream);
250+
251+
$process->wait();
252+
253+
// will echo: 'foobar'
254+
echo $process->getOutput();
255+
233256
Stopping a Process
234257
------------------
235258

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

0 commit comments

Comments
 (0)
0