title: php exec() function and different hosts
body: <p>I have a script that executes a file in a couple of directories down which looks like this:</p>
  
  <pre><code>exec("php-cli $file_path &gt; /dev/null 2&gt;/dev/null &amp;"); //php command-line
  </code></pre>
  
  <p>This works on most hosts but some hosts don't like it and it doesn't run, without generating any error.</p>
  
  <p>For the hosts that this fails on, i use </p>
  
  <pre><code>exec("php $file_path &gt; /dev/null 2&gt;/dev/null &amp;"); //notice the -cli is gone
  </code></pre>
  
  <p>Which works fine.</p>
  
  <p>$file_path is the full path to the file being executed /home/blah/path/blah.php</p>
  
  <p>How can i make this uniform so it works on all servers (unix at least)</p>
  
  <p><em><strong></em>**EDIT*<em>*</em></strong></p>
  
  <p>Well, I'm doing it this way, it is (most likely) not the correct way but it works.</p>
  
  <p>Instead of just using php-cli or php, i use both so if one fails, the other goes through. Either the php is running as cgi or cli and one of these will catch, and since there is no output, there would be no error either. </p>
  
  <pre><code>exec("php-cli $file_path &gt; /dev/null 2&gt;/dev/null &amp;");
  exec("php $file_path &gt; /dev/null 2&gt;/dev/null &amp;");
  </code></pre>
  
  <p>Unless you know a better solution please let me know. Thanks for all your help.</p>