title: How to integrate PHP and R on Windows?
body: <p>Having some issues integrating PHP and R. I am working from this article:</p>
  
  <p><a href="http://www.r-bloggers.com/integrating-php-and-r/" rel="nofollow">http://www.r-bloggers.com/integrating-php-and-r/</a></p>
  
  <p>R is installed and is verified working with our R script:</p>
  
  <pre><code>Rscript C:\inetpub\wwwroot\client\includes\decisionTreePredictor.R 20 10 O 1000 10000 5000 0.2 10.2
  </code></pre>
  
  <p>Printing a single value that is a result of its calculations:</p>
  
  <pre><code>[1] "0"
  </code></pre>
  
  <p>(The path to Rscript.exe is set in the Windows environmental variables)</p>
  
  <p>I have a PHP script in place that is using exec() which tests successfully with commands such as:</p>
  
  <pre><code>$result = exec('dir',$output,$returnVar);
  echo "&lt;br&gt;result ". print_r($result,true);
  echo "&lt;br&gt;output &lt;pre&gt;". print_r($output,true) , "&lt;/pre&gt;";
  echo "&lt;br&gt;return ". print_r($returnVar,true);
  </code></pre>
  
  <p>returning:</p>
  
  <pre><code>result 2 Dir(s) 117,749,354,496 bytes free
  output 
  Array
  (
      [0] =&gt;  Volume in drive C is C_DRIVE
      [1] =&gt;  Volume Serial Number is 7EB2-A074
      [2] =&gt; 
      [3] =&gt;  Directory of C:\inetpub\wwwroot\client\temp
      [4] =&gt; 
      [5] =&gt; 05/17/2014  10:29 PM              .
      [6] =&gt; 05/17/2014  10:29 PM              ..
      [7] =&gt; 05/16/2014  09:24 AM             5,181 dbimporttest.php
      [8] =&gt; 05/17/2014  10:29 PM                 0 routput.txt
      [9] =&gt; 05/17/2014  11:42 PM               701 rscripttest.php
      [10] =&gt; 05/16/2014  04:59 PM               425 whoami.php
      [11] =&gt;                4 File(s)          6,307 bytes
      [12] =&gt;                2 Dir(s)  117,749,354,496 bytes free
  )
  
  
  return 0
  </code></pre>
  
  <p><strong>When I try to run the R script within the exec command, it fails:</strong></p>
  
  <pre><code>$result = exec('Rscript.exe C:\inetpub\wwwroot\client\includes\decisionTreePredictor.R 20 10 O 1000 10000 5000 0.2 10.2',$output,$returnVar);
  echo "&lt;br&gt;result ". print_r($result,true);
  echo "&lt;br&gt;output &lt;pre&gt;". print_r($output,true) , "&lt;/pre&gt;";
  echo "&lt;br&gt;return ". print_r($returnVar,true);
  </code></pre>
  
  <p>Returning:</p>
  
  <pre><code>result 
  output 
  Array
  (
  )
  
  
  return 1
  </code></pre>
  
  <p>I am running:</p>
  
  <ul>
  <li>Windows Server 8 R2 </li>
  <li>IIS 8 </li>
  <li>PHP 5.5 </li>
  <li>R 3.1</li>
  </ul>