Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/230.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
通过php';打开的管道读取时始终被阻塞;s proc_与stream_select一起使用时打开_Php_Select_User Interaction_Proc Open - Fatal编程技术网

通过php';打开的管道读取时始终被阻塞;s proc_与stream_select一起使用时打开

通过php';打开的管道读取时始终被阻塞;s proc_与stream_select一起使用时打开,php,select,user-interaction,proc-open,Php,Select,User Interaction,Proc Open,我所说的是一个需要用户交互的进程,它使用以下代码(PHP5.3/Ubuntu12.04) 我不知道这里发生了什么。我试图在这里实现某种基于web的终端模拟器。欢迎提出任何建议:)很抱歉浪费了你们的时间。我在一段时间后解决了这个问题(很抱歉更新太晚)。由于竞争条件,读取被阻止 我向流程写入数据,并立即检查流的可用性。从不写入块和数据尚未准备好读取(不知何故,即使1字节的数据可用,也需要600毫秒)。因此,我可以通过在写入块的末尾添加sleep(1)来解决这个问题。很抱歉浪费了你们的时间。我在一段时

我所说的是一个需要用户交互的进程,它使用以下代码(PHP5.3/Ubuntu12.04)


我不知道这里发生了什么。我试图在这里实现某种基于web的终端模拟器。欢迎提出任何建议:)

很抱歉浪费了你们的时间。我在一段时间后解决了这个问题(很抱歉更新太晚)。由于竞争条件,读取被阻止


我向流程写入数据,并立即检查流的可用性。从不写入块和数据尚未准备好读取(不知何故,即使1字节的数据可用,也需要600毫秒)。因此,我可以通过在写入块的末尾添加sleep(1)来解决这个问题。

很抱歉浪费了你们的时间。我在一段时间后解决了这个问题(很抱歉更新太晚)。由于竞争条件,读取被阻止


我向流程写入数据,并立即检查流的可用性。从不写入块和数据尚未准备好读取(不知何故,即使1字节的数据可用,也需要600毫秒)。因此,我可以通过在写入块末尾添加sleep(1)来解决这个问题。

您不能用超时重复选择吗?您不能用超时重复选择吗?
$pdes = array(
  0 => array('pipe', 'r'), //child's stdin
  1 => array('pipe', 'w'), //child's stdout
);
$process = proc_open($cmd, $pdes, $pipes);
sleep(1);
if(is_resource($process)){
  while($iter-->0){
    $r=array($pipes[1]);
    $w=array($pipes[0]);
    $e=array();
    if(0<($streams=stream_select($r,$w,$e,2))){
      if($streams){
        if($r){
          echo "reading\n";
          $rbuf.=fread($pipes[1],$rlen);  //reading rlen bytes from pipe
        }else{
          echo "writing\n";
          fwrite($pipes[0],$wbuf."\n");  //writing to pipe
          fflush($pipes[0]);
  }}}}
  fclose($pipes[0]);
  fclose($pipes[1]);
  echo "exitcode: ".proc_close($process)."\n";
}
#include <stdio.h>
int main(){
  char buf[512];
  printf("before input\n");
  scanf("%s",buf);
  printf("after input\n");
  return 0;
}
echo fread($pipes[1],$rlen);   //matching printf before input
fwrite($pipes[0],$wbuf."\n");  //matching scanf
fflush($pipes[0]);
echo fread($pipes[1],$rlen);   //matching printf after input