We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

How can I use the php function system() or exec() in phalcon?

e.g.: system( '"...\Rscript.exe" "....\r_test\r_script.R"', $foobar ) or exec( '"...\Rscript.exe" "....\r_test\r_script.R"', $foobar )

It doesn't work on my server under phalcon. Is there another solution?



145.0k
Accepted
answer

What you mean id doesn't work ? What problem/error you have ?



1.1k

It doesn't run the script and the output is empty.

But only under phalcon.



1.1k

Oops. I did not want set the discussion on solved.

edited Jun '16

?! Those are plain PHP functions, there's no single reason why it wouldn't work under Phalcon. Check your application server configuration (php.ini), whenever you are allowed to execute system or exec functions due to security configuration by your system admin / person who manages application server.

Test it with:

exec('pwd', $status, $rv);

var_dump($status, $rv);
exit;


1.1k

I think I know the problem. The R script-file is in the folder <web APP_PATH>/app/data/r_test/r_script.R and there is no access. There comes access denied!

e.g.:  exec( '"...\Rscript.exe" "'. APP_PATH .'app\data\r_test\r_script.R"', $foobar )

How can I give the access to run/execute the R script ?

You need to go to shell and chmod -v 755 your file.

chmod on exe file ? :)

Uh-oh. Missed that @jurigag :)

Is this yet another Windows use case? No no.... please no!



1.1k

Yes, I tested it on Windows. It works normaly when I used a single file (e.g. with index.php) , but when I jused it in phalcon it does not work.

That is the reason why I think it must be a problem with the rights in the plugin/SecurityPlugin.php :/

But I dont have any idea to fix it.

Why you even use windows ? Use vagrant or something.