Run PHP script in ruby ​​on rails

In one of my Rails applications, I need to execute a PHP file from the Controller of Ruby on Rails application. The PHP file is intended for editing some databases.

Php file located in my "public" folder

Is there any way to do this?

+4
source share
4 answers

If you want to talk to the process IO.popen("php <script>") , use IO.popen("php <script>") . Or you can use the backticks option (not so easy with the markup here), which returns the string that the process writes to stdout. If you do not need a connection, system "php <script>" returns true or false wherever the command was executed, and you have no way to communicate further.

If you have unsafe input, use Array#shelljoin to avoid it.

Why not rewrite the script in ruby?

+1
source

Try `php # {RAILS_ROOT} / public / php_script.php` or% x [" php # {RAILS_ROOT} /public/php_script.php "]

The system command does not work on rails, but some code like the one above should be fine.

+2
source

Ok, does system('php public/php_script.php') ?

+1
source

My problem is solved by this line in my controller

result = D:\\rails\\php\\php.exe -f D:\\Rails\\rails_apps\\project\\public\\df.php po

+1
source

Source: https://habr.com/ru/post/1384103/


All Articles