You get a bonus - 1 coin for daily activity. Now you have 1 coin

What are the differences between shell_exec, system, exec, backticks, and passthru?

Practice




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

To leave a comment

If you have any suggestion, idea, thanks or comment, feel free to write. We really value feedback and are glad to hear your opinion.
To reply

Lectures and tutorial on "Running server side scripts using PHP as an example (LAMP)"

Terms: Running server side scripts using PHP as an example (LAMP)