Anybody please tell me. I want know the different between the exec()
, shell_exec
, system()
and passthru()
function?
I search from php.net unable to get the answers I need.
The shell_exec() function is an inbuilt function in PHP which is used to execute the commands via shell and return the complete output as a string. The shell_exec is an alias for the backtick operator, for those used to *nix. If the command fails return NULL and the values are not reliable for error checking.
system() is just like the C version of the function in that it executes the given command and outputs the result. The system() call also tries to automatically flush the web server's output buffer after each line of output if PHP is running as a server module.
shell_exec() Function: The shell_exec() function is an inbuilt function in PHP that is used to execute the commands via shell and return the complete output as a string. The shell_exec is an alias for the backtick operator, for those used to *nix.
Under Actions, click on the Manage php.ini file: Just after 'disable_functions = ', write out the functions you want to disable (example: exec,passthru,popen). Here is a list of functions that are commonly disabled as a means to improve security: exec.
exec
only returns the last line of the generated output.shell_exec
returns the full output of the command, when the command finished running. system
immediately shows all output, and is used to show text. passthru
also returns output immediately, but is used for binary data. passthru
displays raw data. With both exec
and shell_exec
it is possible to handle the output yourself, while system
and passthru
won't let you customize it and immediately display the output.
A more detailed comparison can be found here.
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.
See PHP - exec() vs system() vs passthru() for more info
Also see php shell_exec() vs exec().
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With