AbstractPipes.php 1.6 KB

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