Windows usa where , sistemi UNIX which per consentire di localizzare un comando. Entrambi restituiranno una stringa vuota in STDOUT se il comando non viene trovato.
PHP_OS è attualmente WINNT per ogni versione di Windows supportata da PHP.
Quindi ecco una soluzione portatile:
/**
 * Determines if a command exists on the current environment
 *
 * @param string $command The command to check
 * @return bool True if the command has been found ; otherwise, false.
 */
function command_exists ($command) {
  $whereIsCommand = (PHP_OS == 'WINNT') ? 'where' : 'which';
  $process = proc_open(
    "$whereIsCommand $command",
    array(
      0 => array("pipe", "r"), //STDIN
      1 => array("pipe", "w"), //STDOUT
      2 => array("pipe", "w"), //STDERR
    ),
    $pipes
  );
  if ($process !== false) {
    $stdout = stream_get_contents($pipes[1]);
    $stderr = stream_get_contents($pipes[2]);
    fclose($pipes[1]);
    fclose($pipes[2]);
    proc_close($process);
    return $stdout != '';
  }
  return false;
}
Su Linux/Mac OS Prova questo:
function command_exist($cmd) {
    $return = shell_exec(sprintf("which %s", escapeshellarg($cmd)));
    return !empty($return);
}
Quindi usalo nel codice:
if (!command_exist('makemiracle')) {
    print 'no miracles';
} else {
    shell_exec('makemiracle');
}
Aggiornamento: Come suggerito da @camilo-martin potresti semplicemente usare:
if (`which makemiracle`) {
    shell_exec('makemiracle');
}
Basato su @jcubic e su quel "che" dovrebbe essere evitato, questa è la multipiattaforma che ho ideato:
function verifyCommand($command) :bool {
  $windows = strpos(PHP_OS, 'WIN') === 0;
  $test = $windows ? 'where' : 'command -v';
  return is_executable(trim(shell_exec("$test $command")));
}