How to integrate PHP and R on Windows? -
having issues integrating php , r. working article:
http://www.r-bloggers.com/integrating-php-and-r/
r installed , verified working our r script:
rscript c:\inetpub\wwwroot\client\includes\decisiontreepredictor.r 20 10 o 1000 10000 5000 0.2 10.2
printing single value result of calculations:
[1] "0"
(the path rscript.exe set in windows environmental variables)
i have php script in place using exec() tests commands such as:
$result = exec('dir',$output,$returnvar); echo "<br>result ". print_r($result,true); echo "<br>output <pre>". print_r($output,true) , "</pre>"; echo "<br>return ". print_r($returnvar,true);
returning:
result 2 dir(s) 117,749,354,496 bytes free output array ( [0] => volume in drive c c_drive [1] => volume serial number 7eb2-a074 [2] => [3] => directory of c:\inetpub\wwwroot\client\temp [4] => [5] => 05/17/2014 10:29 pm . [6] => 05/17/2014 10:29 pm .. [7] => 05/16/2014 09:24 5,181 dbimporttest.php [8] => 05/17/2014 10:29 pm 0 routput.txt [9] => 05/17/2014 11:42 pm 701 rscripttest.php [10] => 05/16/2014 04:59 pm 425 whoami.php [11] => 4 file(s) 6,307 bytes [12] => 2 dir(s) 117,749,354,496 bytes free ) return 0
when try run r script within exec command, fails:
$result = exec('rscript.exe c:\inetpub\wwwroot\client\includes\decisiontreepredictor.r 20 10 o 1000 10000 5000 0.2 10.2',$output,$returnvar); echo "<br>result ". print_r($result,true); echo "<br>output <pre>". print_r($output,true) , "</pre>"; echo "<br>return ". print_r($returnvar,true);
returning:
result output array ( ) return 1
i running:
- windows server 8 r2
- iis 8
- php 5.5
- r 3.1
unable exec() work or output errors usable, decided seek alternative route. using com class seems have given me looking for.
here final, operational code:
$command = 'c:\program files\r\r-3.1.0\bin\rscript.exe c:\inetpub\wwwroot\client\includes\decisiontreepredictor.r 20 10 o 1000 10000 5000 0.2 10.2'; $pcom = new com("wscript.shell"); $pshell = $pcom->exec($command); $sstdout = $pshell->stdout->readall; # standard output $sstderr = $pshell->stderr->readall; # error echo "<pre>$sstdout</pre>";
odd couldn't exec() job seems solution preferred bloggers discussing r/php integration.
anyway, hope solution helps else finds in situation!
p.s. want make sure extension on in php.ini (it off default on install): extension=php_com_dotnet.dll
Comments
Post a Comment