3

How to write the output of an Asynchronous process to the file. I have the following code in my phpunit bootstrap file:

$command = 'exec php ' . $kernel->getRootDir() . '/console '
            . 'xxx:servicebus:start-services --env='
            . $kernel->getEnvironment();

$servicebusCommand = new Symfony\Component\Process\Process($command);
$servicebusCommand->start();

Obviously the code starts a servicebus instance which listens to all the incoming requests to the server. Once the tests are ran, the requests go to the servicebus and it stuck there. I need to see the output of the start servicebus command to see what went wrong.

Any idea how to write the output of the process to some log file?

luchaninov
  • 6,792
  • 6
  • 60
  • 75
Obaid Maroof
  • 1,523
  • 2
  • 19
  • 40

2 Answers2

0

You need to call $servicebusCommand->getIncrementalErrorOutput() and $servicebusCommand->getIncrementalOutput() regularly.

Mantas
  • 4,259
  • 2
  • 27
  • 32
  • 1
    Thanks! would you mind explaining 'regularly' a bit more? I start the process in my bootstrap, and after the process starts, the execution of the bootstrap script terminates. – Obaid Maroof Nov 06 '14 at 11:29
0

Just pass closure to the start or run function

$process->start(function ($type, $buffer) use ($logFile) {
        file_put_contents($logFile, $buffer, FILE_APPEND);
    
        if ('err' === $type) {
                echo 'ERR > '.$buffer;
        } else {
                echo 'OUT > '.$buffer;
        }
});

From here