views:

25

answers:

3

I have a file that is having some multiple dynamic parameters.I want to send these parameters at the time of writing a file in main cron file. Something like this ->

*/15 * * * * /usr/bin/php /a/b/c.php parameter1 parameter2 parameter3 parameter4

Now i tried working this up but my file is not executing. What im concerned about is that how will my php file will fetch these parameters ?? And how will i write this command when there is only 2 parameters to be passes parameter1 and parameter4??? and how will my cron and php will recognoze that which parameter is for which data and all?? please advice!!

A: 
*/15 * * * * "/usr/bin/php /a/b/c.php parameter1 parameter2 parameter3 parameter4"

maybe...

also you can pass it as a query string? p1=123&p2=432&p3=456 within the script you can just do a parse_string to convert it into an array...

Tobias
but how can i send query string with this kind of file calling : /home/abc/xyz/ert.php ???query string is possible in http:// kind of urls but how will i write it in path format???
developer
You can't pass a query string via command line.
Joseph
p1=123-p2:123 ... its possible...
Tobias
A: 

In this case it will be $argv array in your script with those parameters.

Also you can make an executable file with contents:

#!/usr/bin/php
<?
    require('yourscript.php');

And make it executable with chmod +x thisfile. Just not to pass your file name to php interpreter in crontab.

silent
A: 

The way you need to go about making this script work is the following:

In the cron script set the parameters to each be query strings. For example, set p1=1234 as parameter1, etc.

Within the PHP script, you will need to reference the $argv array to get the parameters passed in.

$argv[1] will be parameter1, $argv[2] is parameter2, and so forth.

You can identify which parameter is which by using the explode command to separate the key from the value:

for($x=1; $x < $argc; $x++) {
    list($key, $value) = explode('=', $argv[1]);
    $paramarray[$key] = $value;
}
Joseph