Reputation: 1332
I working in Rails and I need to call to an PHP-script. I can connect to the script like this:
system('php public/myscript.php')
But I need to send some parameters with it. How do I do that?
Thanks
Upvotes: 1
Views: 180
Reputation: 5961
Yes its right way to use system('php public/myscript.php arg1 arg2'
) as SirDarius answered .
but system command will return the true or false in that case.
system() will return TrueClass or FalseClass and display output, try it on console .
I suggest , You can use the open method on any URL to call it, so you can call your PHP script using that:
require 'open-uri'
open('YOUR PHP SCRIPT PATH WITH PARAMETER') do |response|
content = response.read
end
Upvotes: 0
Reputation: 42989
You can provide command-line arguments to your PHP script:
system('php public/myscript.php arg1 arg2')
They will be available from your PHP code like this:
echo $argv[0]; // public/myscript.php
echo $argv[1]; // arg1
echo $argv[2]; // arg2
Upvotes: 3
Reputation: 1932
You can just specify the parameters on the command line, such as system('php -f public/myscript.php argument1 argument2 [...]')
and they will be available in the $argv[]
array, starting from $argv[1]
. See the doc page here for more info.
Upvotes: 1