PHP exec() vs system() vs passthru()

前端 未结 5 1049
别那么骄傲
别那么骄傲 2020-11-22 10:34

What are the differences?

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

PHP.net says tha

5条回答
  •  花落未央
    2020-11-22 11:01

    It really all comes down to how you want to handle output that the command might return and whether you want your PHP script to wait for the callee program to finish or not.

    • exec executes a command and passes output to the caller (or returns it in an optional variable).

    • passthru is similar to the exec() function in that it executes a command . This function should be used in place of exec() or system() when the output from the Unix command is binary data which needs to be passed directly back to the browser.

    • system executes an external program and displays the output, but only the last line.

    If you need to execute a command and have all the data from the command passed directly back without any interference, use the passthru() function.

提交回复
热议问题