Proper shell execution in PHP

前端 未结 4 672
情歌与酒
情歌与酒 2021-02-14 16:53

The problem

I was using a function that made use of proc_open() to invoke shell commands. It seems the way I was doing STDIO was wrong and sometimes cause

4条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-14 17:33

    while($r = stream_select($read, $write, $except, null, $timeout)){
    

    As far as I know this will set $r to the number of changed streams, which may be 0 and the loop would no longer continue. I would personally recode this as described in the PHP manual:

    while(false !== ($r = stream_select($read, $write, $except, null, $timeout))){
    

    As far as your STDIN is concerned if your process is not interactive then the STDIN may not be necessary. What is the process you are executing?

提交回复
热议问题