Proper shell execution in PHP

前端 未结 4 674
情歌与酒
情歌与酒 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:59

    Well, seems a year passed and forgot this thing is still pending!

    However, I wrapped up this mess in a nice PHP class which you can find on Github.

    The main remaining problem is that reading STDERR causes the PHP script to block, so it has been disabled.

    On the bright side, thanks to events and some nice coding (I hope!), one can actually interact with the process being executed (hence the class name, InterExec). So you can have bot-style behavior in PHP.

提交回复
热议问题