| 1 |
<?php |
| 2 |
|
| 3 |
/* |
| 4 |
* This file is part of the Symfony package. |
| 5 |
* |
| 6 |
* (c) Fabien Potencier <fabien@symfony.com> |
| 7 |
* |
| 8 |
* For the full copyright and license information, please view the LICENSE |
| 9 |
* file that was distributed with this source code. |
| 10 |
*/ |
| 11 |
|
| 12 |
/** |
| 13 |
* @author Romain Neutron <imprec@gmail.com> |
| 14 |
* |
| 15 |
* @internal |
| 16 |
*/ |
| 17 |
abstract class Symfony_Process_Pipes_AbstractPipes implements Symfony_Process_Pipes_PipesInterface |
| 18 |
{ |
| 19 |
/** @var array */ |
| 20 |
public $pipes = array(); |
| 21 |
|
| 22 |
/** @var string */ |
| 23 |
protected $inputBuffer = ''; |
| 24 |
/** @var resource|null */ |
| 25 |
protected $input; |
| 26 |
|
| 27 |
/** @var bool */ |
| 28 |
private $blocked = true; |
| 29 |
|
| 30 |
/** |
| 31 |
* {@inheritdoc} |
| 32 |
*/ |
| 33 |
public function close() |
| 34 |
{ |
| 35 |
foreach ($this->pipes as $pipe) { |
| 36 |
fclose($pipe); |
| 37 |
} |
| 38 |
$this->pipes = array(); |
| 39 |
} |
| 40 |
|
| 41 |
/** |
| 42 |
* Returns true if a system call has been interrupted. |
| 43 |
* |
| 44 |
* @return bool |
| 45 |
*/ |
| 46 |
protected function hasSystemCallBeenInterrupted() |
| 47 |
{ |
| 48 |
$lastError = error_get_last(); |
| 49 |
|
| 50 |
// stream_select returns false when the `select` system call is interrupted by an incoming signal |
| 51 |
return isset($lastError['message']) && false !== stripos($lastError['message'], 'interrupted system call'); |
| 52 |
} |
| 53 |
|
| 54 |
/** |
| 55 |
* Unblocks streams |
| 56 |
*/ |
| 57 |
protected function unblock() |
| 58 |
{ |
| 59 |
if (!$this->blocked) { |
| 60 |
return; |
| 61 |
} |
| 62 |
|
| 63 |
foreach ($this->pipes as $pipe) { |
| 64 |
stream_set_blocking($pipe, 0); |
| 65 |
} |
| 66 |
if (null !== $this->input) { |
| 67 |
stream_set_blocking($this->input, 0); |
| 68 |
} |
| 69 |
|
| 70 |
$this->blocked = false; |
| 71 |
} |
| 72 |
} |
| 73 |
|