1

I need to automate daily calls to a single PHP script but passing a different parameter each time (around 30). Is there a neat way to handle this, other than creating an individual cron for each call to the script? THanks for any pointers.

2
  • 3
    What determines which parameter is passed to the script, just the time? Commented May 23, 2011 at 14:48
  • There's an array of around 30 numbers which all need to be passed individually to the script - the params are a number of days, each being used as filters in a query Commented May 23, 2011 at 14:51

3 Answers 3

2

You can run the script using different command line parameters. Check getopt function or $argv/$argc variables.

Sign up to request clarification or add additional context in comments.

Comments

2

The $argv array will hold multiple parameters:

http://php.net/manual/en/reserved.variables.argv.php

<?php var_dump( $argv ); ?> 

Example usage:

$ php cli.php param1 param2 param3 

Output:

array(4) { [0]=> string(7) "cli.php" [1]=> string(6) "param1" [2]=> string(6) "param2" [3]=> string(6) "param3" } 

Comments

0

You could create a parameters.txt file with all 30 or so parameters separated by line breaks. Then create a separate counter.txt file with a 0 in it.

Read the counter.txt file. Read the parameters file, split it by line breaks, and then access the index location indicated by the counter file to get your parameter.

(your file logic here)

Increment the counter, write the new counter to counter.txt (overwrite it), and continue the process, resetting the counter once you have reached your upper limit.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.