Skip to content

Commit bee773e

Browse files
fix: warn and prevent usage of STDIN and STDOUT on Windows due to PHP limitations
1 parent 8285b48 commit bee773e

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/Transports/StdioServerTransport.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,19 @@ public function __construct(
6464
protected $inputStreamResource = STDIN,
6565
protected $outputStreamResource = STDOUT
6666
) {
67+
if (str_contains(PHP_OS, 'WIN') && ($this->inputStreamResource === STDIN && $this->outputStreamResource === STDOUT)) {
68+
$message = 'STDIN and STDOUT are not supported as input and output stream resources'.
69+
'on Windows due to PHP\'s limitations with non blocking pipes.'.
70+
'Please use WSL or HttpServerTransport, or if you are advanced, provide your own stream resources.';
71+
72+
throw new TransportException($message);
73+
}
74+
75+
// if (str_contains(PHP_OS, 'WIN')) {
76+
// $this->inputStreamResource = pclose(popen('winpty -c "'.$this->inputStreamResource.'"', 'r'));
77+
// $this->outputStreamResource = pclose(popen('winpty -c "'.$this->outputStreamResource.'"', 'w'));
78+
// }
79+
6780
if (! is_resource($this->inputStreamResource) || get_resource_type($this->inputStreamResource) !== 'stream') {
6881
throw new TransportException('Invalid input stream resource provided.');
6982
}

0 commit comments

Comments
 (0)