What are the best practices for executing shell scripts using PHP?

When executing shell scripts using PHP, it is important to follow best practices to ensure security and efficiency. One common approach is to use the `exec()` function in PHP, which allows you to run shell commands and scripts. It is recommended to sanitize user input to prevent injection attacks and to carefully handle any output or errors from the shell script.

// Example of executing a shell script using PHP
$scriptPath = '/path/to/your/script.sh';

// Sanitize user input if needed
$userInput = escapeshellarg($userInput);

// Execute the shell script
$output = shell_exec("sh $scriptPath $userInput");

// Check for any errors
if ($output === null) {
    echo "Error executing script";
} else {
    echo "Script output: $output";
}