Jump to content

R code execution from PHP fails only in Browser and not in terminal


phpnewbie007

Recommended Posts

I am trying call an R batch file inside php script from browser. The R script basically generate an imgae and save in a folder. Unfortunately, I could call the R within php (means that no image is saved in  the folder) using BROWSER. But when I run the php script from the commadline, it works and image is saved in the folder.

<?php

exec("Rscript /var/www/html/phil/figs/map.R");

 ?>

Execuition of following R batch code and php codes work and save image in the specified folder from the terminal.

58A-UD3R:~$ php /var/www/html/phil/x.php

58A-UD3R:~$ Rscript /var/www/html/phil/figs/map.R

I totally in confusion why browser cannot successfully save image.  Or is there anythinng need to be change in server for generating image?

Anyone please help me for solving this probelm.

 

Thank You..

 

Just to confirm, http://yourdomain.com/phil/x.php is the small PHP script you are showing, right?

 

Maybe read/write privileges?  What does the following give you?

<?php
echo ('Current script owner: ' . get_current_user().'</br>');

echo(exec("Rscript /var/www/html/phil/figs/map.R").'</br>');

shell_echo(exec("Rscript /var/www/html/phil/figs/map.R").'</br>');

?>

I run with your test php file and it only displayed the user in browser (ie, Current script owner: 'myusername'). But not generated image in the folder. But when I run the same file from terminal, it generated image.

 

I have an HTML form and onclcik a button calls the x.php (which in turn expected to generate and save image). I call the file from url as 'http://localhost/phil/main.html'.

 

So is that a problem with permission?

 

Thanks...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.