File tree Expand file tree Collapse file tree 3 files changed +23
-0
lines changed Expand file tree Collapse file tree 3 files changed +23
-0
lines changed Original file line number Diff line number Diff line change 2929 $ stdio ->end ();
3030});
3131
32+ // input already closed on program start, exit immediately
33+ if (!$ stdio ->isReadable ()) {
34+ $ loop ->cancelTimer ($ timer );
35+ $ stdio ->end ();
36+ }
37+
3238$ loop ->run ();
Original file line number Diff line number Diff line change @@ -14,6 +14,12 @@ public function __construct(LoopInterface $loop)
1414 {
1515 parent ::__construct (STDIN , $ loop );
1616
17+ // support starting program with closed STDIN ("example.php 0<&-")
18+ // the stream is a valid resource and is not EOF, but fstat fails
19+ if (fstat (STDIN ) === false ) {
20+ return $ this ->close ();
21+ }
22+
1723 if ($ this ->isTty ()) {
1824 $ this ->oldMode = shell_exec ('stty -g ' );
1925
Original file line number Diff line number Diff line change @@ -30,6 +30,17 @@ public function testPeriodicExampleWithSleepNoInputQuitsOnEnd()
3030 $ this ->assertNotContains ('you just said: ' , $ output );
3131 }
3232
33+ public function testPeriodicExampleWithClosedInputQuitsImmediately ()
34+ {
35+ $ output = $ this ->execExample ('php 01-periodic.php <&- ' );
36+
37+ if (strpos ($ output , 'said ' ) !== false ) {
38+ $ this ->markTestIncomplete ('Your platform exhibits a closed STDIN bug, this may need some further debugging ' );
39+ }
40+
41+ $ this ->assertNotContains ('you just said: ' , $ output );
42+ }
43+
3344 private function execExample ($ command )
3445 {
3546 chdir (__DIR__ . '/../examples/ ' );
You can’t perform that action at this time.
0 commit comments