If we have a PHP function which makes difficult calculations based on a certain input, for example:
function count_score($var1, $var2, $var3){
// based on $var1, $var2 and $var3 we run
// a 5000-lines long calculation,
// resulting in one $output
return $output;
}
Now, what happens here:
- the function takes about 1 second to run
- there aren't many combinations of $var1, $var2 and $var3 that might be inputted (roughly around 3000)
What I can do:
I can store the result of the function based on every combination and check whether it has been calculated before. I can store this to $_SESSION, per user, so every time the function is called, the results are looked up in the $_SESSION.
However, what if I want to store these results for all users? I can't use $_SESSION then, as it's not shared globally across the site for all users. How can I store it then?
The only time when the results of the calculations are different is when I change the function, which happens about once in 48 hours. Then I can probably manually specify the function revision and check for results of that revision. But how/where do I store all this?
EDIT Optionally, the method should work in CRON (without the http layer), but it's not necessary.