What are the differences between using exec() and passthru() functions in PHP for executing external commands?

The main difference between using exec() and passthru() functions in PHP for executing external commands is how they handle the output of the command. - exec() returns the last line of the command output, while passthru() directly outputs the command output to the browser. - If you need to capture the output of the command for further processing, exec() is preferred. If you simply want to display the output as it is, passthru() is more suitable.

// Using exec() to capture command output
$output = exec('ls -la');
echo $output;

// Using passthru() to directly output command result
passthru('ls -la');