'PHP: How to kinda CATCH exec() WARNINGs & continue execution of main program

I am currently using this command to validate some PHP files.

$op=null; $ret=null; exec("php -l '$file' 2>&1",$op,$ret);

Unfortunately on the customer's shared hosting (linux) it fails with the line below obviously because some commands are disabled:

Warning: exec(): Unable to fork [php -l '/path_to_the_file.php' 2>&1] in /my_program.php on line 559

I want to avoid this Warning at all costs because as soon as I disable debugging, the host shows its 500 error page which completely kills the webpage (for some strange reason).

Try/Catch does not work at all.

    try {
      $op=null; $ret=null; exec("php -l '$file' 2>&1",$op,$ret);
      if($ret != 0) {
        throw new Exception("'$file' failed syntax check");
      }
    } catch(Exception $e) {
        $this->addLog(LOG_ERR, 'syntax error', $e);
        continue;
    }

Any ideas how to avoid this Warning?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source