本文整理汇总了PHP中Cron::save方法的典型用法代码示例。如果您正苦于以下问题:PHP Cron::save方法的具体用法?PHP Cron::save怎么用?PHP Cron::save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cron
的用法示例。
在下文中一共展示了Cron::save方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: poorMansCron
static function poorMansCron()
{
$intervals = array("minute", "five", "fifteen", "hour", "week");
foreach ($intervals as $interval) {
$entity = getEntity(array("type" => "Cron", "metadata_name" => "interval", "metadata_value" => $interval));
if (!$entity) {
$entity = new Cron();
$entity->interval = $interval;
$entity->save();
}
Cron::run($interval, false);
}
return;
}
示例2: run
static function run($interval, $ignore_last_run = true)
{
$phpbin = PHP_BINDIR . "/php";
if ($ignore_last_run) {
shell_exec('echo $phpbin -q ' . SITEPATH . 'cron/' . $interval . '.php | at now');
return;
}
$entity = getEntity(array("type" => "Cron", "metadata_name" => "interval", "metadata_value" => $interval));
if (!$entity) {
$entity = new Cron();
$entity->interval = $interval;
$entity->save();
}
$last_ran = $entity->last_ran;
if (!$last_ran) {
$last_ran = 0;
}
switch ($interval) {
case "minute":
$seconds = 60;
break;
case "five":
$seconds = 60 * 5;
break;
case "fifteen":
$seconds = 60 * 15;
break;
case "hour":
$seconds = 60 * 60;
break;
case "week":
default:
$seconds = 60 * 60 * 24 * 7;
break;
}
$time = time();
if ($time > $last_ran + $seconds) {
$shell = $phpbin . ' -q ' . SITEPATH . 'cron/' . $interval . '.php > /dev/null 2>/dev/null &';
shell_exec($shell);
$last_ran = $time;
$entity = getEntity(array("type" => "Cron", "metadata_name" => "interval", "metadata_value" => $interval));
if ($entity) {
$entity->last_ran = $last_ran;
$entity->save();
}
}
return;
}