What are the differences between shell_exec, system, exec, backticks, and passthru?
Exec – Works on both Windows and Linux. When running in safe_mode, it launches applications only from the directory specified in the safe_mode_exec_dir parameter in php.ini. Usage:
exec("command",$output);
Shell_Exec The equivalent of
shell_exec is using
backticks
$output = shell_exec("command");
SystemThe C-like function system sends its output straight to the browser, which isn't always convenient, so you need to use buffering functions to capture its output:
ob_start();
system("command");
$output = ob_get_contents();
ob_end_clean();
Passthru The main use of the passthru function is when the output of some launched program isn't text and you'd like to send it straight to the browser.
ob_start();
passthru("command");
$output = ob_get_contents();
ob_end_clean();
Comments