PHP 中的 system()、exec() 和 shell_exec() 有什么区别?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10828707/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What are the differences of system(), exec() and shell_exec() in PHP?
提问by Googlebot
It is possible to run an external command by three PHP functions of
可以通过以下三个 PHP 函数运行外部命令
system();
exec();
shell_exec();
but what are their differences? In spite of their specific applications, in most cases, the can be equally used. I am curious to know which is preferred one when they can be equally used. For example, for unzipping a file or compressing a folder (with tar command), which one is preferred (probably from performance point of view)?
但它们的区别是什么?尽管它们有特定的应用,但在大多数情况下,它们都可以同等使用。我很想知道当它们可以平等使用时哪个是首选。例如,对于解压缩文件或压缩文件夹(使用 tar 命令),首选哪一个(可能从性能角度来看)?
UPDATE:In another question, I found a very useful linkdescribing different aspects for these functions. I share the link here, as other may use to better understand security issues and other aspects.
更新:在另一个问题中,我找到了一个非常有用的链接,描述了这些函数的不同方面。我在这里分享链接,因为其他人可能会使用它来更好地了解安全问题和其他方面。
回答by Gavriel
exec— Execute an external program
exec— 执行外部程序
system— Execute an external program and display the output
system— 执行外部程序并显示输出
shell_exec— Execute command via shell and return the complete output as a string
shell_exec— 通过 shell 执行命令并以字符串形式返回完整的输出
so if you don't need the output, I would go with exec.
所以如果你不需要输出,我会和 exec 一起去。
Further details:
更多细节:

