Non-blocking on STDIN in PHP CLI

后端 未结 4 883
死守一世寂寞
死守一世寂寞 2020-12-14 10:07

Is there anyway to read from STDIN with PHP that is non blocking:

I tried this:

stream_set_blocking(STDIN, false);
echo fread(STDIN, 1);         


        
4条回答
  •  一向
    一向 (楼主)
    2020-12-14 10:33

    system('stty cbreak');
    while(true){
        if($char = fread(STDIN, 1)) {
            echo chr(8) . mb_strtoupper($char);
        }
    }
    

提交回复
热议问题