Revision 7578,
1.3 KB
checked in by angelo, 12 years ago
(diff) |
Ticket #3197 - Reduzir tempo de carregamento do modulo Expresso Mail
|
Line | |
---|
1 | Process Component |
---|
2 | ================= |
---|
3 | |
---|
4 | Process executes commands in sub-processes. |
---|
5 | |
---|
6 | In this example, we run a simple directory listing and get the result back: |
---|
7 | |
---|
8 | use Symfony\Component\Process\Process; |
---|
9 | |
---|
10 | $process = new Process('ls -lsa'); |
---|
11 | $process->setTimeout(3600); |
---|
12 | $process->run(); |
---|
13 | if (!$process->isSuccessful()) { |
---|
14 | throw new RuntimeException($process->getErrorOutput()); |
---|
15 | } |
---|
16 | |
---|
17 | print $process->getOutput(); |
---|
18 | |
---|
19 | You can think that this is easy to achieve with plain PHP but it's not especially |
---|
20 | if you want to take care of the subtle differences between the different platforms. |
---|
21 | |
---|
22 | And if you want to be able to get some feedback in real-time, just pass an |
---|
23 | anonymous function to the ``run()`` method and you will get the output buffer |
---|
24 | as it becomes available: |
---|
25 | |
---|
26 | use Symfony\Component\Process\Process; |
---|
27 | |
---|
28 | $process = new Process('ls -lsa'); |
---|
29 | $process->run(function ($type, $buffer) { |
---|
30 | if ('err' === $type) { |
---|
31 | echo 'ERR > '.$buffer; |
---|
32 | } else { |
---|
33 | echo 'OUT > '.$buffer; |
---|
34 | } |
---|
35 | }); |
---|
36 | |
---|
37 | That's great if you want to execute a long running command (like rsync-ing files to a |
---|
38 | remote server) and give feedback to the user in real-time. |
---|
39 | |
---|
40 | Resources |
---|
41 | --------- |
---|
42 | |
---|
43 | You can run the unit tests with the following command: |
---|
44 | |
---|
45 | $ cd path/to/Symfony/Component/XXX/ |
---|
46 | $ composer.phar install --dev |
---|
47 | $ phpunit |
---|
Note: See
TracBrowser
for help on using the repository browser.