In what scenarios is it recommended to use passthru() instead of shell_exec in PHP scripts that run external commands?

When running external commands in PHP scripts, it is recommended to use passthru() instead of shell_exec when you want to directly output the command's result to the browser or terminal without any interference or manipulation. passthru() passes the command output directly to the output stream, making it suitable for scenarios where you want to display the raw output of the command.

<?php
// Example using passthru() to directly output the command result
passthru('ls -l');
?>