Skip to content

Commit 29ce64e

Browse files
committed
Merge branch 'QA'
Signed-off-by: William Desportes <[email protected]>
2 parents c97fd75 + e0da85e commit 29ce64e

2 files changed

Lines changed: 15 additions & 5 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* Fix lexer to not allow numbers with letters (#300)
77
* Add support for INVISIBLE keyword (#292)
88
* Fix the "$" might be a character used in a name (#301)
9+
* Fix use stream_select instead of non-blocking STDIN (#309)
910

1011
## [5.3.1] - 2020-03-20
1112

src/Utils/CLI.php

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
use function in_array;
1717
use function rtrim;
1818
use function stream_get_contents;
19-
use function stream_set_blocking;
19+
use function stream_select;
2020
use function var_export;
2121
use const STDIN;
2222

@@ -260,10 +260,19 @@ public function runTokenize()
260260

261261
public function readStdin()
262262
{
263-
stream_set_blocking(STDIN, false);
264-
$stdin = stream_get_contents(STDIN);
265-
// restore-default block-mode setting
266-
stream_set_blocking(STDIN, true);
263+
$read = [STDIN];
264+
$write = [];
265+
$except = [];
266+
267+
// Assume there's nothing to be read from STDIN.
268+
$stdin = null;
269+
270+
// Try to read from STDIN. Wait 0.2 second before timing out.
271+
$result = stream_select($read, $write, $except, 0, 2000);
272+
273+
if ($result > 0) {
274+
$stdin = stream_get_contents(STDIN);
275+
}
267276

268277
return $stdin;
269278
}

0 commit comments

Comments
 (0)