Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0d416fd

Browse filesBrowse files
committed
added a chapter about the Process component
1 parent 535fc54 commit 0d416fd
Copy full SHA for 0d416fd

File tree

Expand file treeCollapse file tree

3 files changed

+81
-1
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+81
-1
lines changed

‎components/css_selector.rst

Copy file name to clipboardExpand all lines: components/css_selector.rst
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ The CssSelector Component
66

77
The CssSelector Component converts CSS selectors to XPath expressions.
88

9-
109
Installation
1110
------------
1211

‎components/index.rst

Copy file name to clipboardExpand all lines: components/index.rst
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ The Symfony2 Components
88
console
99
css_selector
1010
finder
11+
process
1112
yaml

‎components/process.rst

Copy file name to clipboard
+80Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
.. index::
2+
single: Process
3+
4+
The Process Component
5+
=====================
6+
7+
The Process Component executes commands in sub-processes.
8+
9+
Installation
10+
------------
11+
12+
You can install the component in many different ways:
13+
14+
* Use the official Git repository (https://github.com/symfony/Process);
15+
* Install it via PEAR ( `pear.symfony.com/Process`);
16+
* Install it via Composer (`symfony/process` on Packagist).
17+
18+
Usage
19+
-----
20+
21+
The `:class:Symfony\\Component\\Process\\Process` class allows you to execute
22+
a command in a sub-process::
23+
24+
.. code-block:: php
25+
26+
use Symfony\Component\Process\Process;
27+
28+
$process = new Process('ls -lsa');
29+
$process->setTimeout(3600);
30+
$process->run();
31+
if (!$process->isSuccessful()) {
32+
throw new RuntimeException($process->getErrorOutput());
33+
}
34+
35+
print $process->getOutput();
36+
37+
The ``:method::Symfony\\Component\\Process\\Process:run()`` method takes care
38+
of the subtle differences between the different platforms when executing the
39+
command.
40+
41+
When executing a long running command (like rsync-ing files to a remote
42+
server), you can give feedback to the end user in real-time by passing an
43+
anonymous function to the
44+
``:method::Symfony\\Component\\Process\\Process:run()`` method::
45+
46+
.. code-block:: php
47+
48+
use Symfony\Component\Process\Process;
49+
50+
$process = new Process('ls -lsa');
51+
$process->run(function ($type, $buffer) {
52+
if ('err' === $type) {
53+
echo 'ERR > '.$buffer;
54+
} else {
55+
echo 'OUT > '.$buffer;
56+
}
57+
});
58+
59+
If you want to execute some PHP code in isolation, use the ``PhpProcess``
60+
instead::
61+
62+
.. code-block:: php
63+
64+
use Symfony\Component\Process\PhpProcess;
65+
66+
$process = new PhpProcess(<<<EOF
67+
<?php echo 'Hello World'; ?>
68+
EOF);
69+
$process->run();
70+
71+
.. versionadded:: 2.1
72+
The ``ProcessBuilder`` class has been as of 2.1.
73+
74+
To make your code work better on all platforms, you might want to use the
75+
``:class:Symfony\Component\Process\ProcessBuilder`` class instead::
76+
77+
use Symfony\Component\Process\ProcessBuilder;
78+
79+
$builder = new ProcessBuilder(array('ls', '-lsa'));
80+
$builder->getProcess()->run();

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.