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

When executing external commands in PHP, the main difference between using exec() and passthru() functions lies in how they handle the output of the command. - The exec() function only returns the last line of the command output, making it suitable for capturing the result of the command. - The passthru() function, on the other hand, displays the output of the command directly to the browser, making it useful for scenarios where you want to see the command output in real-time. To capture the output of an external command while still being able to see it in real-time, you can use a combination of both functions in your PHP code.

// Using exec() to capture the output of the command
$output = [];
exec('your_command_here', $output);

// Using passthru() to display the output of the command in real-time
passthru('your_command_here');