This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
symfony/src/Symfony/Component/Process
Fabien Potencier e99dfdf87a Merge branch '2.3' into 2.4
* 2.3:
  [HttpKernel] add use statement for phpdoc
  Disabled the PHPUnit self-update on Travis
  [ClassLoader] simplified phpdoc
  [ClassLoader] Add a __call() method to XcacheClassLoader
  fix some minor typos in tests
  [Yaml] fixed mapping keys containing a quoted #
  Added fixture to test parsing of hash keys ending with a space and #
  [Filesystem Component] mkdir race condition fix #11626
  [Validator] reverted permissions change on translation files
  Fixed Factory services not within the ServiceReferenceGraph.
  [CssSelector] Fix URL to SimonSapin/cssselect repo
  [Validator] Fixed wrong translation keys/messages for Collection constraint. The error messages for a missing field and an unexpected field did not match the Contraint class
  [YAML] resolve variables in inlined YAML
  Disallow abstract definitions from doctrine event listener registration

Conflicts:
	src/Symfony/Bridge/Doctrine/DependencyInjection/CompilerPass/RegisterEventListenersAndSubscribersPass.php
	src/Symfony/Bridge/Doctrine/Tests/DependencyInjection/CompilerPass/RegisterEventListenersAndSubscribersPassTest.php
	src/Symfony/Bundle/FrameworkBundle/EventListener/SessionListener.php
	src/Symfony/Component/Filesystem/Filesystem.php
2014-08-31 05:18:18 +02:00
..
Exception fixed CS 2013-10-30 09:33:58 +01:00
Tests Merge branch '2.3' into 2.4 2014-08-31 05:18:18 +02:00
.gitignore Added missing files .gitignore 2013-07-21 14:12:18 +02:00
CHANGELOG.md [Process] updated the CHANGELOG 2013-08-03 08:07:42 +02:00
composer.json updated version to 2.4 2013-05-16 09:54:39 +02:00
ExecutableFinder.php [Process] Fixes issue #11421 2014-07-19 17:29:08 -06:00
LICENSE update year on licenses 2014-01-07 08:19:25 -05:00
PhpExecutableFinder.php [Process] fixed HHVM usage on the CLI 2014-03-30 09:33:30 +02:00
PhpProcess.php made phpdoc types consistent with those defined in Hack 2014-04-15 07:41:45 +02:00
phpunit.xml.dist removed defaults from PHPUnit configuration 2014-07-07 12:13:42 +02:00
Process.php Merge branch '2.3' into 2.4 2014-07-28 15:13:16 +02:00
ProcessBuilder.php add missing docblock for ProcessBuilder::addEnvironmentVariables() 2014-07-06 17:05:33 +02:00
ProcessPipes.php bug #11120 [2.3][Process] Reduce I/O load on Windows platform (romainneutron) 2014-07-23 17:11:31 +02:00
ProcessUtils.php [Process] Add validation on Process input 2014-05-17 23:49:26 +02:00
README.md [Process] Minor README update 2014-06-11 09:56:44 +02:00

Process Component

Process executes commands in sub-processes.

In this example, we run a simple directory listing and get the result back:

use Symfony\Component\Process\Process;

$process = new Process('ls -lsa');
$process->setTimeout(3600);
$process->run();
if (!$process->isSuccessful()) {
    throw new RuntimeException($process->getErrorOutput());
}

print $process->getOutput();

You can think that this is easy to achieve with plain PHP but it's not especially if you want to take care of the subtle differences between the different platforms.

And if you want to be able to get some feedback in real-time, just pass an anonymous function to the run() method and you will get the output buffer as it becomes available:

use Symfony\Component\Process\Process;

$process = new Process('ls -lsa');
$process->run(function ($type, $buffer) {
    if (Process::ERR === $type) {
        echo 'ERR > '.$buffer;
    } else {
        echo 'OUT > '.$buffer;
    }
});

That's great if you want to execute a long running command (like rsync-ing files to a remote server) and give feedback to the user in real-time.

Resources

You can run the unit tests with the following command:

$ cd path/to/Symfony/Component/Process/
$ composer.phar install
$ phpunit