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
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions 38 src/Symfony/Component/Process/NullProcessPipes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\Process;

use Symfony\Component\Process\Exception\RuntimeException;

/**
* NullProcessPipes allow redirecting output to dev/null without a subshell. Useful for processes that communicate
* over other means.
*/
class NullProcessPipes extends ProcessPipes
{
/**
* Returns an array of descriptors for the use of proc_open.
*
* @return array
*/
public function getDescriptors()
{
$nullfile = defined('PHP_WINDOWS_VERSION_BUILD') ? 'NUL' : '/dev/null';
return array(

array('pipe', 'r'), // stdin
array('file', $nullfile, 'a+'), // stdout
array('file', $nullfile, 'a+'), //stderr
);
}
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra line break

13 changes: 12 additions & 1 deletion 13 src/Symfony/Component/Process/Process.php
Original file line number Diff line number Diff line change
Expand Up @@ -991,14 +991,25 @@ public function checkTimeout()
}
}

/**
* Sets the process pipes to use.
*
* @param ProcessPipes $pipes
*/
public function setProcessPipes(ProcessPipes $pipes) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

run php-cs-fixer

$this->processPipes = $pipes;
}

/**
* Creates the descriptors needed by the proc_open.
*
* @return array
*/
private function getDescriptors()
{
$this->processPipes = new ProcessPipes($this->useFileHandles);
if (!$this->processPipes) {
$this->processPipes = new ProcessPipes($this->useFileHandles);
}
$descriptors = $this->processPipes->getDescriptors();

if (!$this->useFileHandles && $this->enhanceSigchildCompatibility && $this->isSigchildEnabled()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

/**
* Runs a php script that will dump a large amount of output and then quit.
*/

for ($i = 0; $i < 100000; $i++) {
echo "Lorem ipsum dolor sit amet\n";
}
26 changes: 26 additions & 0 deletions 26 src/Symfony/Component/Process/Tests/NullProcessPipesTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php


namespace Symfony\Component\Process\Tests;

use Symfony\Component\Process\NullProcessPipes;
use Symfony\Component\Process\Process;

class NullProcessPipesTest extends \PHPUnit_Framework_TestCase {
public function testProcessCompletesWithNullPipes() {
// Without null pipes the pipe would fill and the process will never complete
$process = new Process('php ' . __DIR__ . '/HeavyOutputtingProcess.php');
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do have the special if in NullProcessPipes for win, but skip the test here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, My initial commit didn't support windows, the test was written for that - then i found this issue which had the windows friendly code, so it was added. Removed the skip.

$this->markTestSkipped('Windows does not support NullProcessPipes');
}
$process->setProcessPipes(new NullProcessPipes());
$process->start();

while($process->isRunning()) {
usleep(100e3);
}

// No output!
$this->assertEquals('', $process->getOutput());
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.