PHP exec()与system()与passthru()

问题描述:

有什么区别?

每个功能是否有特定情况或原因?如果可以,您能举一些例子吗?

Is there a specific situation or reason for each function? If yes, can you give some examples of those situations?

PHP.net说,它们用于执行外部程序. 参见参考 从我看到的示例中,我看不出任何明显的区别.

PHP.net says that they are used to execute external programs. see reference From the examples I see, I don't see any obvious difference.

如果我仅运行脚本(bash或python),那么建议我使用哪个功能?

If I were to simply run a script (bash or python), which function do you recommend me to use?

它们的用途略有不同.

  • exec() 用于调用系统命令,也许用于处理您自己输出.
  • system() 用于执行系统命令并立即显示输出-大概是文字.
  • passthru() 用于执行您希望原始的系统命令返回-大概是二进制文件.

无论如何,我建议您不要使用其中任何一个.它们都产生高度不可移植的代码.

Regardless, I suggest you not use any of them. They all produce highly unportable code.