Windows で PHP スクリプトを使用して、チェス エンジンと通信しています。次のように接続を確立しています。
$descriptorspec = array(
0 => array("pipe", "r"), // stdin is a pipe that the child will read from
1 => array("pipe", "w"), // stdout is a pipe that the child will write to
2 => array("file","./error.log","a")
);
$resource = proc_open("stockfish.exe", $descriptorspec, $pipes, null, array());
次のようにコマンドをエンジンに送信できます。
fwrite($pipes[0], "uci" . PHP_EOL);
そして、私はこのようなエンジン出力を読みました:
stream_get_contents($pipes[1]);
問題は、次のように stdin パイプを閉じるまでエンジン出力を読み取れないことです。
fclose($pipes[0]);
つまり、エンジンとやり取りしたいときはいつでも (proc_open を使用して) 接続を開いたり閉じたりする必要があります。
接続を常に開いたままにするにはどうすればよいですか?