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 link describing different aspects for these functions. I share the link here, as other may use to better understand security issues and other aspects.
更新:在另一个问题中,我发现了一个非常有用的链接,用于描述这些函数的不同方面。我在这里分享链接,因为其他可能用来更好地理解安全问题和其他方面。
1 个解决方案
#1
87
exec — Execute an external program
执行一个外部程序
system — Execute an external program and display the output
系统-执行一个外部程序并显示输出
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:
进一步的细节:
- http://php.net/manual/en/function.exec.php
- http://php.net/manual/en/function.exec.php
- http://php.net/manual/en/function.system.php
- http://php.net/manual/en/function.system.php
- http://php.net/shell_exec
- http://php.net/shell_exec
#1
87
exec — Execute an external program
执行一个外部程序
system — Execute an external program and display the output
系统-执行一个外部程序并显示输出
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:
进一步的细节:
- http://php.net/manual/en/function.exec.php
- http://php.net/manual/en/function.exec.php
- http://php.net/manual/en/function.system.php
- http://php.net/manual/en/function.system.php
- http://php.net/shell_exec
- http://php.net/shell_exec