What is the best way to refresh some script function every XX minutes?

85 views Asked by At

I am working on football odds website for first time.

I am getting xml data from an online xml feeder, parsing xml data using PHP and send that data to mysql database, from another php file i get that data and print it on html document.

Xml feeder has time limits for each function, for example: time limit for League is 3600s, time limit for Live Fixture is 25s etc..

I send data using just one file called as sendxmldata.php, there is functions like: SendLeaguesToDb(), SendFixturesToDb() etc..

And now i want to run these functions every XX-XXXX seconds, so each function has different time limit.

How i can to run that functions every XX seconds, i need to run it and when users are not on website?

What is the best way to do this?

Using something like Cron Job or how? If is answer yes, use something like Cron, is there way to run an function from file for 25s, and another from same file for 3600s? Or i need for every function or time_limit create new php file to run? There is very much functions.

Thanks.

1

There are 1 answers

2
monxas On BEST ANSWER

You can create two cronjobspointing to the same file as @jQuery.PHP.Magento.com pointed out. You can pass an argument to choose witch function to call:

1 * * * * /path_to_php/cronjob.php variable1=test variable2=test variable3=test 

You would then use parse_str() to set and access the paramaters:

<?php parse_str($argv[n]); ?>

to use timeout as an parameter:

    1 * * * * /path_to_php/cronjob.php timeout=30

and to read it:

<?php $timeout = parse_str($argv[0]); ?>