In the context of PHP development, what are the recommended approaches for handling and troubleshooting issues related to integrating external scripts, like Perl, into PHP code?

When integrating external scripts like Perl into PHP code, it is important to ensure that the paths to the external scripts are correctly specified and that the scripts are executable. Troubleshooting can involve checking file permissions, verifying the paths, and ensuring that the scripts are properly configured to work with PHP.

// Example of integrating an external Perl script into PHP code
$perlScriptPath = '/path/to/external/script.pl';

// Check if the Perl script exists and is executable
if (file_exists($perlScriptPath) && is_executable($perlScriptPath)) {
    // Execute the Perl script
    $output = shell_exec("perl $perlScriptPath");
    echo $output;
} else {
    echo "Error: Perl script not found or not executable.";
}