chris pattas
chris pattas

Reputation: 97

Pass and get variables between PHP and R

I have a php file that runs as a cron job. That file gets all the football games of the day with curl once per day and stores them in a database. So the table nextgames has the following:

HomeTeam, AwayTeam, League, Odds of various things such as 1,X,2 under etc (doesn't matter).

For each of those games I want to run some R code. So basically, inside the php script I need to run a command like:

exec("Rscript <path>/myscript.R");

My first question is: In that script I need to pass HomeTeam, AwayTeam and League. So how do I pass those variables to the script?

My second question is: That script has as a result a 7x7 matrix that represents the probabilities for each of the teams score 0, 1, 2, 3, 4, 5 or 6 goals. How do I get that data back to php?

PS: I can't install rapache to the webhost I am atm.

Upvotes: 1

Views: 2807

Answers (1)

sberry
sberry

Reputation: 132018

Check out the example on the proc_open docs page: http://php.net/manual/en/function.proc-open.php

What I would suggest is outputting the contents of your matrix as some portable format, such as JSON (it appears R can do JSON). Then just json_decode the output from the R script.

Upvotes: 4

Related Questions