source: branches/2.5/prototype/library/Symfony/Component/Process/README.md @ 7578

Revision 7578, 1.3 KB checked in by angelo, 12 years ago (diff)

Ticket #3197 - Reduzir tempo de carregamento do modulo Expresso Mail

Line 
1Process Component
2=================
3
4Process executes commands in sub-processes.
5
6In 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
19You can think that this is easy to achieve with plain PHP but it's not especially
20if you want to take care of the subtle differences between the different platforms.
21
22And if you want to be able to get some feedback in real-time, just pass an
23anonymous function to the ``run()`` method and you will get the output buffer
24as 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
37That's great if you want to execute a long running command (like rsync-ing files to a
38remote server) and give feedback to the user in real-time.
39
40Resources
41---------
42
43You 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.