* 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\Pipes;
use Symfony\Component\Process\Process;
* UnixPipes implementation uses unix pipes as handles.
* @author Romain Neutron <imprec@gmail.com>
class UnixPipes extends AbstractPipes
private $haveReadSupport;
public function __construct($ttyMode, $ptyMode, $input, $haveReadSupport)
$this->ttyMode = (bool) $ttyMode;
$this->ptyMode = (bool) $ptyMode;
$this->haveReadSupport = (bool) $haveReadSupport;
parent::__construct($input);
public function __destruct()
public function getDescriptors()
if (!$this->haveReadSupport) {
$nullstream = fopen('/dev/null', 'c');
['file', '/dev/tty', 'r'],
['file', '/dev/tty', 'w'],
['file', '/dev/tty', 'w'],
if ($this->ptyMode && Process::isPtySupported()) {
public function getFiles()
public function readAndWrite($blocking, $close = false)
// let's have a look if something changed in streams
set_error_handler([$this, 'handleError']);
if (($r || $w) && false === stream_select($r, $w, $e, 0, $blocking ? Process::TIMEOUT_PRECISION * 1E6 : 0)) {
// if a system call has been interrupted, forget about it, let's try again
// otherwise, an error occurred, let's reset pipes
if (!$this->hasSystemCallBeenInterrupted()) {
// prior PHP 5.4 the array passed to stream_select is modified and
// lose key association, we have to find back the key
$read[$type = array_search($pipe, $this->pipes, true)] = '';
$data = @fread($pipe, self::CHUNK_SIZE);
} while (isset($data[0]) && ($close || isset($data[self::CHUNK_SIZE - 1])));
if (!isset($read[$type][0])) {
if ($close && feof($pipe)) {
unset($this->pipes[$type]);
public function haveReadSupport()
return $this->haveReadSupport;
public function areOpen()
return (bool) $this->pipes;