PHP 中的 exec()、shell_exec、system() 和 passthru() 函数有什么不同?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20072696/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 02:51:11  来源:igfitidea点击:

What is different between exec(), shell_exec, system() and passthru() functions in PHP?

php

提问by Developer

Anybody please tell me. I want know the different between the exec(), shell_exec, system()and passthru()function?

有人请告诉我。我想知道之间的不同exec()shell_execsystem()passthru()功能?

I search from php.netunable to get the answers I need.

我从php.net搜索无法得到我需要的答案。

回答by Patrick Kostjens

  • execonly returns the last line of the generated output.
  • shell_execreturns the full output of the command, when the command finished running.
  • systemimmediately shows all output, and is used to show text.
  • passthrualso returns output immediately, but is used for binary data. passthrudisplays raw data.
  • exec只返回生成输出的最后一行。
  • shell_exec当命令完成运行时,返回命令的完整输出。
  • system立即显示所有输出,用于显示文本。
  • passthru也立即返回输出,但用于二进制数据。passthru显示原始数据。

With both execand shell_execit is possible to handle the output yourself, while systemand passthruwon't let you customize it and immediately display the output.

execshell_exec它可以处理自己的输出,而systempassthru不会让你自定义,并立即显示输出。

A more detailed comparison can be found here.

可以在此处找到更详细的比较。

回答by vogomatix

passthru is used for returning binary data instead of ascii. A typical example is where an image manipulation program is returning an image instead of text data.

passthru 用于返回二进制数据而不是 ascii。一个典型的例子是图像处理程序返回图像而不是文本数据。

See PHP - exec() vs system() vs passthru()for more info

有关更多信息,请参阅PHP - exec() vs system() vs passthru()

Also see php shell_exec() vs exec().

另请参阅php shell_exec() 与 exec()