php要点cron,php – 如何使用cron作业安排动态功能?

我想知道如何安排动态(自动填充数据)功能在保存的时间每天自动运行?

假设我有一个表单,一旦单击该按钮,它就会将数据发送到函数,该函数会发布数据.我只想自动化,这样我就不必按下按钮了.

foreach($Class->retrieveData as $data)

{

'.$data['name'].'

'.$data['description'].'

}

?>

现在,表单将数据传递给函数.

if(isset($_POST['post_data'])) // if post_data button is clicked then it runs myFunction()

{

myFunction();

}

myFunction()

{

$name = $_POST['name'];

$description = $_POST['description'];

}

我尝试了以下操作,但问题是Cron Job只能运行整个.php文件,而我正在检索从MySQL运行的已保存时间.

foreach($Class->getTime() as $timeData)

{

$timeHour = $timeData['timeHour'];

$timeMinute = $timeData['timeMinute'];

$hourMin = date('H:i');

$timeData = ''.$timeHour.':'.$timeMinute.'';

if($hourMin == $timeData)

{

run myFunction.

}

}

$hourMin是当前小时:分钟,它与从Mysql自动运行的已保存时间相匹配.因此,如果$hourMin == $timeData,那么该函数将运行.

如果$hourMin等于$timeData,如何运行Cron Job来自动运行myFunction()?

所以…

List 1 = is to be runned at 10am

List 2 = is to be runned at 12pm

List 3 = is to be runned at 2pm

上午10点,下午12点,下午2点是从MySQL检索但是基于每个列表ID的$timeHour和$timeMinute.

编辑

@randomSeed,

1) I can schedule cron jobs.

2) $name and $description will all be arrays, so the following is what I am trying to accomplish.

$name = array(

'Jon',

'Steven',

'Carter'

);

$description = array(

'Jon is a great person.',

'Steven has an outgoing character.',

'Carter is a horrible person.'

);

如果预定的时间是正确的,我想解析$name和$description中的第一个数组.

在数据库中,我有以下内容

postDataTime table

+----+---------+----------+------------+--------+

| iD | timeDay | timeHour | timeMinute | postiD |

+--------------------------------------+--------+

| 1 | * | 9 | 0 | 21 |

|----|---------|----------|------------|--------|

| 2 | * | 10 | 30 | 22 |

|----|---------|----------|------------|--------|

| 3 | * | 11 | 0 | 23 |

+----|---------+----------+------------+--------+

iD = auto incremented on upload.

timeDay = * is everyday (cron job style)

timeHour = Hour of the day to run the script

timeMinute = minute of the hour to run script

postiD = this is the id of the post that is located in another table (n+1 relationship)

if(time() == 10:30(time from MySQL postiD = 22))

{

// run myFunction with the data that is retrieved for that time ex:

$postiD = '22';

$name = 'Steven';

$description = 'Steven has an outgoing character.';

// the above is what will be in the $_POST from the form and will be

// sent to the myFunction()

}

我只想根据保存到MySQL的时间安排所有内容,就像我在最顶层显示的那样(postDataTime表). (我会展示我曾经尝试过的东西,但是我已经搜索了无数个小时的例子来说明我想要完成的事情,但我找不到任何东西,我尝试的东西也不起作用.)

我以为我可以使用exec()函数,但从它看起来不允许我运行函数,否则我会做以下..

$time = '10:30';

if($time == time())

{

exec(myFunction());

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值