PHP中的system(),exec()和shell_exec()有什么区别? [英] What are the differences of system(), exec() and shell_exec() in PHP?

查看:314
本文介绍了PHP中的system(),exec()和shell_exec()有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以通过以下三个PHP函数运行外部命令

It is possible to run an external command by three PHP functions of

system();
exec();
shell_exec();

但是它们有什么区别?尽管它们有特定的应用,但在大多数情况下,它们可以同等使用.我很好奇知道什么时候可以优先使用它们.例如,要解压缩文件或压缩文件夹(使用tar命令),哪个是首选的(可能是从性能的角度来看)?

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)?

更新:在另一个问题中,我发现了一个非常有用的

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.

推荐答案

exec —执行外部程序

系统-执行外部程序并显示输出

system — Execute an external program and display the output

shell_exec —通过shell执行命令并以字符串形式返回完整输出

shell_exec — Execute command via shell and return the complete output as a string

所以如果您不需要输出,我会选择exec.

so if you don't need the output, I would go with exec.

更多详细信息:

  • http://php.net/manual/en/function.exec.php
  • http://php.net/manual/en/function.system.php
  • http://php.net/shell_exec

这篇关于PHP中的system(),exec()和shell_exec()有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆