为一个PHP文件运行多个cron作业

时间:2017-08-19 16:37:06

标签: php cron

我在8:00使用cron jobs。我希望我的文件以不同的值运行3次

  

示例:

test.php?id=1
test.php?id=2
test.php?id=3

如何在8:00同时在cron jobs中运行顶级文件?

3 个答案:

答案 0 :(得分:1)

您需要将params添加到php cli脚本并阅读$ argv以获取此参数http://php.net/manual/en/reserved.variables.argv.php例如

python schema.py db init --directory models/migrations

答案 1 :(得分:0)

使用id字段作为数组。对于前 -

$ids =array('1','2','3');

比使用循环,并调用该函数。对于前 -

foreach($ids as $id){
    $this->CronFunction($id);
}

这样,您的代码将同时以三个不同的值执行。无需为所有三个值创建单独的文件。

答案 2 :(得分:0)

<?php
$myarray = array();
$myarray[] = 1;
$myarray[] = 2;
$myarray[] = 3;
foreach($myarray as $myarr){
    $d = $myarr;
    page_code($d);  //this function call page code in every loop and pass different value
}

function page_code($id){
    //Insert page code inside this function
}
?>

使用所有可能的值创建数组($ myarray)。并从循环内部的函数调用页面代码。不需要运行不同的crone。所有ID都以单个cron运行。这段代码对我有用。感谢