Skip to content

Commit 6f1e608

Browse files
authored
Merge pull request #126 from clue-labs/legacy-unbuffered
Work around reading from unbuffered pipe stream in legacy PHP < 5.4.28 and PHP < 5.5.12
2 parents 5223048 + 8a394f0 commit 6f1e608

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/DuplexResourceStream.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function __construct($stream, LoopInterface $loop, $readChunkSize = null,
6060
// This does not affect the default event loop implementation (level
6161
// triggered), so we can ignore platforms not supporting this (HHVM).
6262
// Pipe streams (such as STDIN) do not seem to require this and legacy
63-
// PHP < 5.4 causes SEGFAULTs on unbuffered pipe streams, so skip this.
63+
// PHP versions cause SEGFAULTs on unbuffered pipe streams, so skip this.
6464
if (function_exists('stream_set_read_buffer') && !$this->isLegacyPipe($stream)) {
6565
stream_set_read_buffer($stream, 0);
6666
}
@@ -201,14 +201,18 @@ public function handleData($stream)
201201
/**
202202
* Returns whether this is a pipe resource in a legacy environment
203203
*
204+
* This works around a legacy PHP bug (#61019) that was fixed in PHP 5.4.28+
205+
* and PHP 5.5.12+ and newer.
206+
*
204207
* @param resource $resource
205208
* @return bool
209+
* @link https://github.com/reactphp/child-process/issues/40
206210
*
207211
* @codeCoverageIgnore
208212
*/
209213
private function isLegacyPipe($resource)
210214
{
211-
if (PHP_VERSION_ID < 50400) {
215+
if (PHP_VERSION_ID < 50428 || (PHP_VERSION_ID >= 50500 && PHP_VERSION_ID < 50512)) {
212216
$meta = stream_get_meta_data($resource);
213217

214218
if (isset($meta['stream_type']) && $meta['stream_type'] === 'STDIO') {

src/ReadableResourceStream.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function __construct($stream, LoopInterface $loop, $readChunkSize = null)
6363
// This does not affect the default event loop implementation (level
6464
// triggered), so we can ignore platforms not supporting this (HHVM).
6565
// Pipe streams (such as STDIN) do not seem to require this and legacy
66-
// PHP < 5.4 causes SEGFAULTs on unbuffered pipe streams, so skip this.
66+
// PHP versions cause SEGFAULTs on unbuffered pipe streams, so skip this.
6767
if (function_exists('stream_set_read_buffer') && !$this->isLegacyPipe($stream)) {
6868
stream_set_read_buffer($stream, 0);
6969
}
@@ -154,14 +154,18 @@ public function handleData()
154154
/**
155155
* Returns whether this is a pipe resource in a legacy environment
156156
*
157+
* This works around a legacy PHP bug (#61019) that was fixed in PHP 5.4.28+
158+
* and PHP 5.5.12+ and newer.
159+
*
157160
* @param resource $resource
158161
* @return bool
162+
* @link https://github.com/reactphp/child-process/issues/40
159163
*
160164
* @codeCoverageIgnore
161165
*/
162166
private function isLegacyPipe($resource)
163167
{
164-
if (PHP_VERSION_ID < 50400) {
168+
if (PHP_VERSION_ID < 50428 || (PHP_VERSION_ID >= 50500 && PHP_VERSION_ID < 50512)) {
165169
$meta = stream_get_meta_data($resource);
166170

167171
if (isset($meta['stream_type']) && $meta['stream_type'] === 'STDIO') {

0 commit comments

Comments
 (0)